package com.herench.bs.agent.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.herench.bs.agent.IOutpatientClinicAgent;
import com.herench.bs.dao.*;
import com.herench.bs.support.CleverClinicContext;
import com.herench.bs.support.HttpClientSupport;
import com.herench.bs.support.ResponseMessage;
import com.herench.bs.support.WsClientFactory;
import com.herench.bs.transfer.*;
import com.herench.bs.utils.AuthHelper;
import com.herench.bs.utils.DataFormatUtils;
import com.herench.bs.utils.GetInformationByIdCardUtil;
import com.herench.bs.utils.IdGenerator;
import org.apache.cxf.endpoint.Client;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;


import java.math.BigDecimal;
import java.util.*;

/**
 * Created by ThinkPad on 2017/8/30.
 */
@Component
@Transactional(readOnly = true)
public class OutpatientClinicAgent implements IOutpatientClinicAgent {

    //    public static final String HIS_WS_URL = "http://10.0.0.132:5527/BITCService.asmx?wsdl";
    //public static final String HIS_WS_URL = "http://oa.herench.com:48451/BitcService.asmx?wsdl";
//    public static final String HIS_WS_URL = "http://61.181.76.107:8077/BITCService.asmx?wsdl";
//    public static final String HIS_WS_URL = "http://192.168.0.109:9002/platformService?wsdl";

    @Value("${his_ws_url}")
    private String hisWsUrl;

    @Value("${callMethod}")
    private String callMethod;


    // ceshi
//    public static final String HIS_WS_URL = "http://111.33.68.62:8072/platformService?wsdl";
    //sizhongxin//
//    public static final String HIS_WS_URL = "http://168.192.1.43:8025/BITCService.asmx?wsdl";
//    public static final String HIS_WS_URL = "http://192.168.200.160:5527/BITCService.asmx?wsdl";

    //   xkzhengshi public static final String HIS_WS_URL = "http://192.168.200.164:8089/BITCService.asmx?wsdl";
    public static final String APPOINT_WS_URL = "http://10.0.0.132:5526/BitcAppService.asmx?wsdl";


    @Autowired
    private CleverClinicContext cleverClinicContext;

    @Autowired
    private IDeptDao deptDao;

    @Autowired
    private IDeptClassTypeDao deptClassTypeDao;

    @Autowired
    protected IPersonDao personDao;

    @Autowired
    private IClinicAppointmentRecordDao clinicAppointmentRecordDao;

    @Autowired
    private IDoctorDao doctorDao;

    @Autowired
    private IBillingRecordDao billingRecordDao;

    @Autowired
    private IClinicChargeDetailsRecordDao clinicChargeDetailsRecordDao;

    @Autowired
    private IClinicChargeRecordDao clinicChargeRecordDao;

    /**
     * 查询出诊科室
     *
     * @param channelCode  渠道编码
     * @param hospitalCode 医院编码
     * @param state        状态 1：只预约；2：只当日；3 都出
     * @return 出诊科室列表
     */
    @Override
    public Map<String, Object> loadVisitDepts(String channelCode, String hospitalCode, String state) {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> params = new HashMap<>(16);

        List<Map<String, Object>> depts = deptDao.find(params);
        List<Map<String, Object>> deptClassList = deptClassTypeDao.find(params);
        if (depts == null) {
            depts = new ArrayList<>();
        }
        if (deptClassList != null) {
            for (Map<String, Object> deptClassMap : deptClassList) {
                for (Map<String, Object> deptMap : depts) {
                    if (deptClassMap.get("deptClassCode").equals(deptMap.get("deptClassType"))) {
                        List<Map<String, Object>> subDepts = (List<Map<String, Object>>) deptClassMap.get("subDepts");
                        if (subDepts == null) {
                            subDepts = new ArrayList<>();
                            deptClassMap.put("subDepts", subDepts);
                        }
                        deptMap.remove("alive");
                        deptMap.remove("special");
                        deptMap.remove("specialContent");
                        deptMap.remove("deptAddress");
                        deptMap.remove("introduce");
                        deptMap.remove("hospitalName");
                        deptMap.remove("hospitalCode");
                        deptMap.remove("state");
                        deptMap.remove("deptClassType");
                        deptMap.remove("deptClassName");
                        subDepts.add(deptMap);
                    }
                }
                List<Map<String, Object>> subDeptsTemp = (List<Map<String, Object>>) deptClassMap.get("subDepts");
                if (subDeptsTemp != null && subDeptsTemp.size() >= 2) {
                    Collections.sort(subDeptsTemp, new Comparator<Map<String, Object>>() {
                        @Override
                        public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                            return o1.get("sort").toString().compareTo(o2.get("sort").toString());
                        }
                    });
                }
                deptClassMap.remove("alive");
                deptClassMap.remove("hospitalCode");
                deptClassMap.remove("hospitalName");
            }
        }
        res.put("depts", deptClassList);
        res.put(ResponseMessage.RES_CODE, "0");
        res.put(ResponseMessage.MESSAGE_OUT, "操作成功");
        res.put(ResponseMessage.MESSAGE_IN, "操作成功");
        res.put(ResponseMessage.MESSAGE, "操作成功");
        return res;
    }

    /**
     * 查询预约科室排班数据
     *
     * @param channelCode  渠道编码
     * @param hospitalCode 医院编码
     * @param deptCode     科室编码
     * @return 执行后的数据
     */
    @Override
    public Map<String, Object> loadDeptScheduling(String channelCode, String hospitalCode, String deptCode, String appointDate) throws Exception {
        Map<String, Object> res = new HashMap<>();
        String method = "send";
        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
        Transfer transfer = new AppointScheduleTransfer(method, client, "GetRegistScheduleRange");
        Map<String, Object> params = new HashMap<>();
        Date date = new Date();
        int dateHourMinute = Integer.parseInt(DataFormatUtils.getHourMinuteString(date).replace(":", ""));
        int startAmount = 1;
        int endAmount = 6;
        if (dateHourMinute >= 1200) {
            startAmount = 2;
            endAmount = 7;
        }
        String start = appointDate;
        String end = appointDate;
        if (appointDate == null || "".equals(appointDate)) {
            Calendar calendar = Calendar.getInstance();
            calendar.add(Calendar.DAY_OF_YEAR, startAmount);
            start = DataFormatUtils.getSimpleTimeString(calendar.getTime());
            calendar.add(Calendar.DAY_OF_YEAR, endAmount);
            end = DataFormatUtils.getSimpleTimeString(calendar.getTime());
        }
        params.put("start", start);
        params.put("end", end);
        params.put("deptCode", deptCode);
        Map<String, Object> resultMap = transfer.transfer(params);
        List<Map<String, Object>> dataList = (List<Map<String, Object>>) resultMap.get("data");
        List<Map<String, String>> schDateList = new ArrayList<>();
        if (appointDate == null || "".equals(appointDate)) {
            schDateList = (List<Map<String, String>>) resultMap.get("schDateList");
        } else {
            for (int i = startAmount; i <= endAmount; i++) {
                Map<String, String> schDateTreeMap = new TreeMap<>();
                Calendar calendar = Calendar.getInstance();
                calendar.add(Calendar.DAY_OF_YEAR, i);
                String schDateValue = DataFormatUtils.getSimpleTimeString(calendar.getTime());
                String schDateKey = DataFormatUtils.getSimpleDayString(schDateValue);
                schDateTreeMap.put(schDateKey, schDateValue);
                for (Map.Entry<String, String> entry : schDateTreeMap.entrySet()) {
                    Map<String, String> dateMap = new HashMap<>();
                    dateMap.put("key", entry.getKey());
                    dateMap.put("value", entry.getValue());
                    String text = DataFormatUtils.getWeekOfDate(DataFormatUtils.parserDay(entry.getValue()));
                    dateMap.put("text", text);
                    schDateList.add(dateMap);
                }
            }
        }
        if (dataList != null) {
            for (Map<String, Object> el : dataList) {
                List<Map<String, Object>> schemeList = (List<Map<String, Object>>) el.get("schemeList");
                if (schemeList != null) {
                    for (Map<String, Object> temp : schemeList) {
                        Map<String, Object> daoParams = new HashMap<>();
                        daoParams.put("doctorCode", temp.get("docId"));
                        daoParams.put("hospitalCode", hospitalCode);
                        Map<String, Object> resDoctorDao = doctorDao.findOne(daoParams);
                        String major = "无";
                        String introduce = "无";
                        String docSex = "未知";
                        String docTitle = "未知";
                        if (resDoctorDao != null) {
                            major = (String) resDoctorDao.get("major");
                            introduce = (String) resDoctorDao.get("introduce");
                            docSex = (String) resDoctorDao.get("sex");
                            temp.put("docPhoto", resDoctorDao.get("iconUrl"));
                            docTitle = (String) resDoctorDao.get("titleCode");
                        }
                        temp.put("docSex", docSex);
                        temp.put("docTitle", Dialect.getDoctorTitleName(docTitle));
                        temp.put("major", major);
                        temp.put("introduce", introduce);
                        temp.put("sort", 1);
                    }
                    Collections.sort(schemeList, new Comparator<Map<String, Object>>() {
                        @Override
                        public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                            return (int) o1.get("sort") - (int) o2.get("sort");
                        }
                    });
                }
            }
        } else {
            dataList = new ArrayList<>();
        }
        res.put("dataList", dataList);
        res.put("schDateList", schDateList);
        res.put(ResponseMessage.RES_CODE, "0");
        res.put(ResponseMessage.MESSAGE_IN, "查询排班数据成功");
        res.put(ResponseMessage.MESSAGE, "查询排班数据成功");
        res.put(ResponseMessage.MESSAGE_OUT, "查询排班数据成功");
        return res;
    }


    /**
     * 查询预约医生的排班数据
     *
     * @param channelCode  渠道编码
     * @param hospitalCode 医院编码
     * @param deptCode     科室编码
     * @param doctorCode   医生编码
     * @return 执行后的数据
     */
    @Override
    public Map<String, Object> loadDoctorScheduling(String channelCode, String hospitalCode, String deptCode, String doctorCode, String schDate, String startDate, String endDate) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        String method = "send";
        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
        Transfer transfer = new DoctorAppointScheduleTransfer(method, client, "GetAllRegistHourCollect");
        Map<String, Object> params = new HashMap<>(16);
//        if (StringUtils.hasLength(schDate)) {
//            schDate = DataFormatUtils.transDayStrSpace(schDate);
//            params.put("start", schDate);
//            params.put("end", schDate);
//        } else {
//            Calendar calendar = Calendar.getInstance();
//            calendar.add(Calendar.DAY_OF_YEAR, 1);
//            String start = DataFormatUtils.getSimpleTimeString(calendar.getTime());
//            if (!StringUtils.hasLength(schDate)) {
        //               schDate = start;
//           }
//            calendar.add(Calendar.DAY_OF_YEAR, 14);
        //           String end = DataFormatUtils.getSimpleTimeString(calendar.getTime());
//            params.put("start", start);
//            params.put("end", end);
//        }
        params.put("startDate", startDate);
        params.put("endDate", endDate);
        params.put("deptCode", deptCode);
        params.put("doctorCode", doctorCode);
        params.put("schDate", schDate);
        params.put("hospitalCode", hospitalCode);
        Map<String, Object> resultMap = transfer.transfer(params);
        resultMap.put("schDate", schDate);
        Map<String, Object> resDoctorDao = doctorDao.findOne(params);
        Map<String, Object> reshospitalDeptDao = deptDao.findOne(params);
        String major = "无";
        String introduce = "无";
        String titleCode = "无";
//        List<Map<String, Object>> schemeList = (List<Map<String, Object>>) resultMap.get("clinicDateList");
        if (resDoctorDao != null) {
            titleCode = (String) resDoctorDao.get("titleCode");
            resultMap.put("major", resDoctorDao.get("major"));
            resultMap.put("introduce", resDoctorDao.get("introduce"));
            resultMap.put("doctorCode", doctorCode);
            resultMap.put("doctorName", resDoctorDao.get("doctorName"));
            resultMap.put("docSex", resDoctorDao.get("sex"));
            resultMap.put("deptCode", deptCode);
            resultMap.put("deptName", reshospitalDeptDao.get("deptName"));
            resultMap.put("categorCode", titleCode);
            resultMap.put("docPhoto", resDoctorDao.get("iconUrl"));
//            List<Map<String, Object>> schemeList = (List<Map<String, Object>>) resultMap.get("clinicDateList");
//            if (schemeList != null) {
//                for (Map<String, Object> temp : schemeList) {
//                    resultMap.put("appointType", temp.get("clinicType"));
//                }
//                }
            resultMap.put("appointType", resultMap.get("clinicType"));
            resultMap.put("categorName", resultMap.get("categorName"));
            resultMap.put("titleName", Dialect.getDoctorTitleName(titleCode));
//            resultMap.put("categorName", Dialect.getDoctorTitleName(titleCode));
//            resultMap.put("docPhoto", resDoctorDao.get("iconUrl"));
            resultMap.put("schStateName", "预约挂号");
        }
// else {
//            resultMap.put("major", major);
//            resultMap.put("introduce", introduce);
//            resultMap.put("doctorCode", doctorCode);
//            resultMap.put("doctorName", "普诊");
//            resultMap.put("deptCode", deptCode);
//            resultMap.put("deptName", reshospitalDeptDao.get("deptName"));
//            resultMap.put("categorCode", "2");
//            resultMap.put("categorName", "普诊");
//            resultMap.put("appointType", "普诊");
//            resultMap.put("docSex", "无");
//            resultMap.put("docPhoto", "http://39.106.103.34:9002/bs/image/index.png");
//            resultMap.put("schStateName", "预约挂号");
//
//       }
        res.put(ResponseMessage.RES_CODE, "0");
        res.put(ResponseMessage.MESSAGE_IN, "查询排班数据成功");
        res.put(ResponseMessage.MESSAGE, "查询排班数据成功");
        res.put(ResponseMessage.MESSAGE_OUT, "查询排班数据成功");
        res.putAll(resultMap);

        return res;
    }

    /**
     * 查询当天科室排班数据
     *
     * @param channelCode  渠道编码
     * @param hospitalCode 医院编码
     * @param deptCode     科室编码
     * @return 执行后的数据
     */
    @Override
    public Map<String, Object> loadCurrentDeptScheduling(String channelCode, String hospitalCode, String deptCode) throws Exception {

        Map<String, Object> res = new HashMap<>(16);
        String method = "send";
        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
        Transfer transfer = new
                RegistScheduleTransfer(method, client, "GetRegistSchedule");
        Map<String, Object> params = new HashMap<>(16);
        // 获取当前日期
        String start = DataFormatUtils.getSimpleTimeString(new Date());
        // 获取当前日期
        String end = DataFormatUtils.getSimpleTimeString(new Date());
        params.put("start", start);
        params.put("end", end);
        params.put("deptCode", deptCode);
        Map<String, Object> resultMap = transfer.transfer(params);
        List<Map<String, Object>> resDataList = (List<Map<String, Object>>) resultMap.get("resDataList");
        if (resDataList != null) {
            for (Map<String, Object> element : resDataList) {
                List<Map<String, Object>> schemeList = (List<Map<String, Object>>) element.get("schemeList");
                if (schemeList != null) {
                    for (Map<String, Object> temp : schemeList) {
                        Map<String, Object> daoParams = new HashMap<>(16);
                        daoParams.put("doctorCode", temp.get("docId"));
                        daoParams.put("hospitalCode", hospitalCode);
                        Map<String, Object> resDoctorDao = doctorDao.findOne(daoParams);
                        String major = "无";
                        String introduce = "无";
                        String titleCode = "无";
                        if (resDoctorDao != null) {
                            major = (String) resDoctorDao.get("major");
                            introduce = (String) resDoctorDao.get("introduce");
                            titleCode = (String) resDoctorDao.get("titleCode");
                            temp.put("docPhoto", resDoctorDao.get("iconUrl"));
                        }
                        temp.put("major", major);
                        temp.put("introduce", introduce);
                        temp.put("docTitle", titleCode);
                        temp.put("docTitleName", Dialect.getDoctorTitleName(titleCode));
                    }
                }
            }
        }
        res.put("dataList", resDataList);
        res.put(ResponseMessage.RES_CODE, "0");
        res.put(ResponseMessage.MESSAGE_IN, "查询科室排班数据成功");
        res.put(ResponseMessage.MESSAGE, "查询科室排班数据成功");
        res.put(ResponseMessage.MESSAGE_OUT, "查询科室排班数据成功");


        return res;
    }

    /**
     * 查询当日医生的排班数据
     *
     * @param channelCode  渠道编码
     * @param hospitalCode 医院编码
     * @param deptCode     科室编码
     * @param docCode      医生编码
     * @return 执行后的数据
     */
    @Override
    public Map<String, Object> loadCurrentDoctorScheduling(String channelCode, String hospitalCode, String deptCode, String docCode) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        String method = "send";
        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
        Transfer transfer = new DoctorRegistSchedulingTransfer(method, client, "GetRegistSchedule");
        Map<String, Object> params = new HashMap<>(16);
        // 获取当前日期
        String start = DataFormatUtils.getSimpleTimeString(new Date());
        // 获取当前日期
        String end = DataFormatUtils.getSimpleTimeString(new Date());
        params.put("start", start);
        params.put("end", end);
        params.put("deptCode", deptCode);
        params.put("doctorCode", docCode);
        params.put("hospitalCode", hospitalCode);
        Map<String, Object> resultMap = transfer.transfer(params);
        List<Map<String, Object>> resDataList = (List<Map<String, Object>>) resultMap.get("resDataList");
        if (resDataList != null) {
            for (Map<String, Object> element : resDataList) {
                Map<String, Object> daoParams = new HashMap<>(16);
                daoParams.put("doctorCode", element.get("docId"));
                daoParams.put("hospitalCode", hospitalCode);
                Map<String, Object> resDoctorDao = doctorDao.findOne(daoParams);
                Map<String, Object> resDeptDao = deptDao.findOne(params);
                String major = "无";
                String introduce = "无";
                String titleCode = "无";
                String docSex = "无";
                String docPhoto = "无";
                if (resDoctorDao != null) {
                    major = (String) resDoctorDao.get("major");
                    introduce = (String) resDoctorDao.get("introduce");
                    titleCode = (String) resDoctorDao.get("titleCode");
                    docSex = (String) resDoctorDao.get("sex");
                    element.put("docPhoto", resDoctorDao.get("iconUrl"));
                    element.put("deptName", resDeptDao.get("deptName"));
                }
                element.put("docSex", docSex);
                element.put("major", major);
                element.put("introduce", introduce);
                element.put("docTitle", titleCode);
                element.put("docTitleName", Dialect.getDoctorTitleName(titleCode));
            }
        }
        if (docCode != null) {
            Map<String, Object> resDoctorDao = doctorDao.findOne(params);
            Map<String, Object> resDeptDao = doctorDao.findOne(params);
            String titleCode = "无";
            if (resDoctorDao != null) {
                titleCode = (String) resDoctorDao.get("titleCode");
                res.put("docSex", resDoctorDao.get("sex"));
                res.put("major", resDoctorDao.get("major"));
                res.put("deptName", resDeptDao.get("deptName"));
                res.put("introduce", resDoctorDao.get("introduce"));
                res.put("docName", resDoctorDao.get("doctorName"));
                res.put("docPhoto", resDoctorDao.get("iconUrl"));
                res.put("deptCode", resDeptDao.get("deptCode"));
                res.put("docTitleName", Dialect.getDoctorTitleName(titleCode));
            }
        }
        res.put("dataList", resDataList);
        res.put(ResponseMessage.RES_CODE, "0");
        res.put(ResponseMessage.MESSAGE_IN, "查询医生排班数据成功");
        res.put(ResponseMessage.MESSAGE, "查询医生排班数据成功");
        res.put(ResponseMessage.MESSAGE_OUT, "查询医生排班数据成功");


        return res;
    }

    /**
     * 查询分时段号源信息
     *
     * @param channelCode  渠道编码
     * @param hospitalCode 医院编码
     * @param scheduleDate 排班日期
     * @param doctorCode   医生编码
     * @param deptCode     科室编码
     * @param period       时段
     * @return 查询数据
     */
    @Override
    public Map<String, Object> loadTimePeriodDoctorScheduling(String channelCode, String hospitalCode, String scheduleDate, String doctorCode, String deptCode, String period) {
        return null;
    }

    /**
     * 验证身份信息接口
     *
     * @param channelCode  渠道编码
     * @param hospitalCode 医院编码
     * @param idCard       身份证号
     * @return 核对结果
     */
    @Override
    public Map<String, Object> checkIdentity(String channelCode, String hospitalCode, String idCard) {
        return null;
    }

    /**
     * 验证就诊卡信息
     *
     * @param channelCode  渠道编码
     * @param hospitalCode 医院编码
     * @param idCard       身份证号
     * @param cardId       卡id
     * @return 验证结果
     */
    @Override
    public Map<String, Object> checkTreatmentCardInfo(String channelCode, String hospitalCode, String idCard, String cardId) {
        return null;
    }

    /**
     * 预约
     *
     * @param channelCode  渠道编码
     * @param hospitalCode 医院编码
     * @param doctorCode   医生编码
     * @param deptCode     科室编码
     * @param scheduleDate 预约日期
     * @param timeDesc     时段
     * @param regFee       挂号费
     * @param clinicFee    诊查费
     * @param otherFee     其他费用
     * @param clinicCharge 总费用=挂号费+诊查费+其他费用
     * @param username     预约账号
     * @param cardId       卡id
     * @param feeType      挂号收费模式 0:预约时未扣费 1:预约时已扣费  不为空
     * @param idCard       预约患者身份证号
     * @param beginTime    时段开始时间
     * @param endTime      时段结束时间
     * @param chargeType   费别
     * @return 预约结果及信息
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> doAppoint(String channelCode, String hospitalCode, String doctorCode, String deptCode, String scheduleDate, String timeDesc, String regFee,
                                         String clinicFee, String otherFee, String clinicCharge, String username,
                                         String cardId, String feeType, String idCard, String beginTime, String endTime, String chargeType) throws Exception {
        Map<String, Object> res = new LinkedHashMap<>();
        String method = "send";
        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
        Transfer transfer = new DoAppointTransfer(method, client, "DoAppoint");
        Map<String, Object> params = new HashMap<>(16);
        params.put("hospitalCode", hospitalCode);
        params.put("doctorCode", doctorCode);
        params.put("deptCode", deptCode);
        params.put("scheduleDate", scheduleDate);
        params.put("timeDesc", timeDesc);
        params.put("regFee", regFee);
        params.put("clinicFee", clinicFee);
        params.put("otherFee", otherFee);
        params.put("clinicCharge", clinicCharge);
        params.put("phone", username);
        params.put("cardId", cardId);
        params.put("feeType", feeType);
        params.put("idCard", idCard);
        params.put("beginTime", beginTime);
        params.put("endTime", endTime);
        params.put("chargeType", chargeType);
        params.put("personId", cardId);
        Map<String, Object> personMap = personDao.findOne(params);
        if (personMap == null) {
            throw new RuntimeException("未找到身份证：" + idCard + " 的患者");
        }
        params.put("sex", personMap.get("sex"));
        params.put("name", personMap.get("name"));
        params.put("dateOfBirth", DataFormatUtils.getSimpleTimeString((Date) personMap.get("dateOfBirth")));
        Map<String, Object> resultMap = transfer.transfer(params);
        if (Dialect.getSuccessfulState().equals(resultMap.get(ResponseMessage.RES_CODE))) {
            Map<String, Object> addMap = new HashMap<>(16);
            String id = DataFormatUtils.getTimeStringNoSpace(new Date()) + hospitalCode + channelCode + IdGenerator.getSixRandNum();
            addMap.put("id", id);
            addMap.put("channelCode", channelCode);
            addMap.put("hospitalCode", hospitalCode);
            addMap.put("appointId", resultMap.get("appointId"));
            addMap.put("username", username);
            addMap.put("personId", idCard);
            addMap.put("idCard", idCard);
            addMap.put("name", personMap.get("name"));
            addMap.put("phone", personMap.get("phone"));
            addMap.put("cardId", cardId);
            addMap.put("appointDate", resultMap.get("appointDate"));
            addMap.put("beginTime", resultMap.get("reportStartTime"));
            addMap.put("endTime", resultMap.get("reportEndTime"));
            addMap.put("period", beginTime + "~" + endTime);
            addMap.put("createTime", DataFormatUtils.getTimeString(new Date()));
            addMap.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
            addMap.put("deptCode", deptCode);
            addMap.put("doctorCode", doctorCode);
            addMap.put("patientType", chargeType);
            addMap.put("doctorTitleCode", Dialect.getClinicTypeCode((String) resultMap.get("clinicType")));
            addMap.put("ampm", Dialect.getAmpmCode(timeDesc));
            String innerSort = (String) resultMap.get("registOrder");
            if (StringUtils.hasLength(innerSort)) {
                addMap.put("innerSort", innerSort);
            }
            addMap.put("state", "0");
            //"1"预约挂号
            addMap.put("appointmentType", "1");
            addMap.put("amount", regFee);
            addMap.put("totalCost", regFee);
            addMap.put("clinicLabel", resultMap.get("clinicLabel"));
            clinicAppointmentRecordDao.add(addMap);
            res.put("recordId", id);
            res.put("channelCode", channelCode);
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "预约挂号成功");
            res.put(ResponseMessage.MESSAGE, resultMap.get("message"));
            res.put(ResponseMessage.MESSAGE_OUT, "预约挂号成功");
        } else {
            String executeMessage = (String) resultMap.get("message");
            res.put(ResponseMessage.RES_CODE, "-9");
            res.put(ResponseMessage.MESSAGE_IN, executeMessage);
            res.put(ResponseMessage.MESSAGE, executeMessage);
            res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
        }
        return res;
    }

    /**
     * 更新预约号的状态(提供非患者使用终端使用)
     *
     * @param channelCode     渠道编码
     * @param hospitalCode    医院编码
     * @param appointmentCode 预约id(院内)
     * @param userPersonId    预约账号id
     * @param idCard          身份证号
     * @param state           状态值
     * @return 执行结果
     */
    @Override
    public Map<String, Object> refreshAppointRecord(String channelCode, String hospitalCode, String appointmentCode, String userPersonId, String idCard, String state) {
        return null;
    }

    /**
     * 根据身份证号查询预约记录
     *
     * @param channelCode  渠道编码
     * @param hospitalCode 医院编码
     * @param userPersonId 挂号用户id
     * @param idCard       身份证号
     * @return 预约记录
     */
    @Override
    public Map<String, Object> loadAppointRecords(String channelCode, String hospitalCode, String userPersonId, String idCard) throws Exception {
        Map<String, Object> res = new HashMap<>();
        String method = "send";
        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
        Transfer transfer = new LoadingAppointRecordTransfer(method, client, "GetAppointMessageById");
        Map<String, Object> params = new HashMap<>();
        params.put("idCard", idCard);
        Map<String, Object> resultMap = transfer.transfer(params);

        if (Dialect.getSuccessfulState().equals(resultMap.get(ResponseMessage.RES_CODE))) {
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "查询成功");
            res.put(ResponseMessage.MESSAGE, "查询成功");
            res.put(ResponseMessage.MESSAGE_OUT, "查询成功");
            res.putAll(resultMap);
        } else {
            String executeMessage = (String) resultMap.get("message");
            res.put(ResponseMessage.RES_CODE, "-10");
            res.put(ResponseMessage.MESSAGE_IN, executeMessage);
            res.put(ResponseMessage.MESSAGE, executeMessage);
            res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
        }

        return res;
    }

    /**
     * 根据身份证查询预约记录
     *
     * @param channelCode  渠道编码
     * @param hospitalCode 医院编码
     * @param idCard       身份证号
     * @return 预约记录
     */
    @Override
    public Map<String, Object> loadAppointRecords(String channelCode, String hospitalCode, String idCard) {

        return null;
    }

    /**
     * 根据用户查询预约记录
     *
     * @param channelCode  渠道编码
     * @param hospitalCode 医院编码
     * @param userPersonId 挂号用户id
     * @return 预约记录
     */
    @Override
    public Map<String, Object> loadAllAppointRecords(String channelCode, String hospitalCode, String userPersonId) {
        return null;
    }

    /**
     * 医生停诊
     *
     * @param hospitalCode 医院编码
     * @param stopData     停诊数据 包含字段（号表日期，号表名称，时段，科室代码，医生编码等）
     * @return
     */
    @Override
    public Map<String, Object> appointStop(String hospitalCode, List<Map<String, Object>> stopData) {
        return null;
    }

    /**
     * 预约报道
     *
     * @param channelCode         渠道编码
     * @param hospitalCode        医院编码
     * @param appointmentCode     预约编码
     * @param hisClinicAppointsId HIS预约ID
     * @param userPersonId        挂号用户id
     * @param recordId            挂号ID
     * @return 预约报道结果
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> checkAppointmentState(String channelCode, String hospitalCode, String appointmentCode, String hisClinicAppointsId, String patientId, String userPersonId, String recordId) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        String method = "send";
        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
        Transfer transfer = new CheckAppointmentStateTransfer(method, client, "AppointSignIn");
        Map<String, Object> params = new HashMap<>(16);
        params.put("hisClinicAppointsId", hisClinicAppointsId);
        params.put("patientId", patientId);
        //自费：D；
        params.put("chargeType", "D");
        params.put("insurNo", "");
        params.put("idCard", userPersonId);
        params.put("insuranceType", "");
        params.put("payType", "");
        params.put("mtType", "");
        Map<String, Object> resMap = transfer.transfer(params);
        if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
            res.put("ifPay", "0");
            res.put("subject", "挂号费");
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "成功");
            res.put(ResponseMessage.MESSAGE, "成功");
            res.put(ResponseMessage.MESSAGE_OUT, "成功");
            Map<String, Object> modifyParam = new HashMap(16);
            modifyParam.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
            modifyParam.put("visitNo", resMap.get("visitNo"));
            modifyParam.put("rcptNo", resMap.get("rcptNo"));
            modifyParam.put("tranNo", resMap.get("tranNo"));
            modifyParam.put("insurVisitId", resMap.get("insurVisitId"));
            modifyParam.put("insurPay", resMap.get("insurPay"));
            modifyParam.put("insurAccountPay", resMap.get("accountPay"));
            modifyParam.put("ownPay", resMap.get("ownPay"));
            modifyParam.put("hisClinicAppointsId", hisClinicAppointsId);
            modifyParam.put("state", "5");
            modifyParam.put("totalCost", resMap.get("clinicCharge"));
            modifyParam.put("id", recordId);
            modifyParam.put("appointId", appointmentCode);
            clinicAppointmentRecordDao.modify(modifyParam);
        } else {
            String executeMessage = (String) resMap.get("message");
            res.put(ResponseMessage.RES_CODE, "-16");
            res.put(ResponseMessage.MESSAGE_IN, executeMessage);
            res.put(ResponseMessage.MESSAGE, executeMessage);
            res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
        }
        return res;
    }

    /**
     * 预约号生成支付订单
     *
     * @param channelCode
     * @param hospitalCode
     * @param appointmentCode
     * @param userPersonId    挂号用户id
     * @return 执行结果
     */
    @Override
    public Map<String, Object> generateOrdersForAppointment(String channelCode, String hospitalCode, String appointmentCode, String userPersonId) {
        return null;
    }

    /**
     * 预约报道支付确认接口(提供给支付平台支付完成之后回调)
     *
     * @param channelCode  渠道编码
     * @param hospitalCode 医院编码
     * @param recordId     挂号ID
     * @param openId       支付用户唯一ID：微信用户唯一ID、支付宝用户唯一ID、银行卡号
     * @param orderId      订单ID
     * @param patientId    患者ID
     * @param userPersonId 用户ID
     * @param orderFee     支付金额
     * @param payTime      支付时间
     * @param payType      支付类别
     * @param tradeNo      交易流水
     * @return
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> payConfirmForAppointment(String channelCode, String hospitalCode, String recordId, String openId, String orderId, String patientId, String userPersonId, String orderFee, String payTime, String payType, String tradeNo) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> params = new HashMap<>(16);
        Map<String, Object> daoRes = new HashMap<>(16);
        params.put("channelCode", channelCode);
        params.put("id", recordId);
        daoRes = clinicAppointmentRecordDao.findOne(params);
        if (daoRes != null) {
            Map<String, Object> resMap = new HashMap<>(16);
            String method = "send";
            Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
            Transfer transfer = new PayConfirmForAppointmentTransfer(method, client, "AppointTranConfirm");
            params.putAll(daoRes);
            params.put("patientId", patientId);
            params.put("orderFee", orderFee);
            params.put("tradeNo", tradeNo);
            params.put("payType", payType);
            resMap = transfer.transfer(params);
            if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
                Map<String, Object> billParams = new HashMap<>(16);
                Map<String, Object> daoParams = new HashMap<>(16);
                res.putAll(resMap);
                res.put(ResponseMessage.RES_CODE, "0");
                res.put(ResponseMessage.MESSAGE_IN, "预约报道支付确认成功");
                res.put(ResponseMessage.MESSAGE, "预约报道支付确认成功");
                res.put(ResponseMessage.MESSAGE_OUT, "预约报道支付确认成功");
                daoParams.put("channelCode", channelCode);
                daoParams.put("tranNo", res.get("tranNo"));
                daoParams.put("state", "2");
                daoParams.put("id", recordId);
                daoParams.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
                clinicAppointmentRecordDao.modify(daoParams);
                Map<String, Object> findOneRes = clinicAppointmentRecordDao.findOne(daoParams);
                billParams.put("billId", orderId);
                billParams.put("hospitalCode", hospitalCode);
                billParams.put("doctorCode", findOneRes.get("doctorCode"));
                billParams.put("deptCode", findOneRes.get("deptCode"));
                billParams.put("appointmentCode", recordId);
                billParams.put("appointDate", DataFormatUtils.getTimeString((Date) findOneRes.get("appointDate")));
                billParams.put("transactNo", res.get("tranNo"));
                billParams.put("orderId", findOneRes.get("rcptNo"));
                billParams.put("patientId", patientId);
                billParams.put("visitNo", findOneRes.get("visitNo"));
                billParams.put("prescriptionNum", "");
                billParams.put("channelCode", channelCode);
                billParams.put("personId", findOneRes.get("personId"));
                billParams.put("idCard", findOneRes.get("idCard"));
                billParams.put("personName", findOneRes.get("name"));
                billParams.put("phone", userPersonId);
                billParams.put("username", userPersonId);
                billParams.put("cardType", payType);
                billParams.put("cardNum", openId);
                billParams.put("patientType", findOneRes.get("patientType"));
                billParams.put("totalCost", findOneRes.get("totalCost"));
                billParams.put("tradeNo", tradeNo);
                billParams.put("cost", orderFee);
                billParams.put("insuranceAmount", findOneRes.get("insurPay"));
                billParams.put("personalAmount", findOneRes.get("insurAccountPay"));
                billParams.put("otherAmount", orderFee);
                billParams.put("payWay", payType);
                billParams.put("visitDate", DataFormatUtils.getTimeString((Date) findOneRes.get("appointDate")));
                billParams.put("createTime", DataFormatUtils.getTimeString(new Date()));
                billParams.put("payTime", payTime);
                billParams.put("billTypeCode", "1");
                billParams.put("payType", payType);
                billParams.put("state", "0");
                billingRecordDao.add(billParams);
            } else {
                String executeMessage = (String) resMap.get("message");
                res.put(ResponseMessage.RES_CODE, "-21");
                res.put(ResponseMessage.MESSAGE_IN, executeMessage);
                res.put(ResponseMessage.MESSAGE, executeMessage);
                res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
            }
        } else {
            res.put(ResponseMessage.RES_CODE, "-3");
            res.put(ResponseMessage.MESSAGE, "未找到相关记录");
            res.put(ResponseMessage.MESSAGE_IN, "未找到相关记录");
            res.put(ResponseMessage.MESSAGE_OUT, "未找到相关记录");
        }
        return res;
    }

    /**
     * 取消预约
     *
     * @param channelCode  渠道编码
     * @param hospitalCode 医院编码
     * @param id           预约id
     * @param userPersonId 挂号用户id
     * @param idCard       挂号用户身份证号码
     * @return 取消预约结果
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> doCancelAppoint(String channelCode, String hospitalCode, String id, String userPersonId, String idCard) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> params = new HashMap<>(16);
        params.put("idCard", idCard);
        params.put("id", id);
        params.put("username", userPersonId);
        Map<String, Object> clinicAppointRecord = clinicAppointmentRecordDao.findOne(params);
        if (clinicAppointRecord == null) {
            res.put(ResponseMessage.RES_CODE, "-3");
            res.put(ResponseMessage.MESSAGE, "未找到相关记录");
            res.put(ResponseMessage.MESSAGE_IN, "未找到相关记录");
            res.put(ResponseMessage.MESSAGE_OUT, "未找到相关记录");
        } else {
            String method = "send";
            Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
            params.put("appointId", clinicAppointRecord.get("appointId"));
            Transfer transfer = new CancelAppointmentTransfer(method, client, "DoCancelAppoint");
            Map<String, Object> resultMap = transfer.transfer(params);
            String executeMessage = (String) resultMap.get("message");
            if (Dialect.getSuccessfulState().equals(resultMap.get(ResponseMessage.RES_CODE))) {
                res.put(ResponseMessage.RES_CODE, "0");
                res.put(ResponseMessage.MESSAGE_IN, executeMessage);
                res.put(ResponseMessage.MESSAGE, executeMessage);
                res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
                res.put("channelCode", channelCode);
                res.put("id", id);
                clinicAppointRecord.put("state", "5");
                this.clinicAppointmentRecordDao.modify(clinicAppointRecord);
            } else {
                res.put(ResponseMessage.RES_CODE, "-11");
                res.put(ResponseMessage.MESSAGE_IN, executeMessage);
                res.put(ResponseMessage.MESSAGE, executeMessage);
                res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
            }
        }

        return res;
    }

    /**
     * 根据recordId取消预约
     *
     * @param channelCode
     * @param hospitalCode
     * @param recordId
     * @return
     * @throws Exception
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> doCancelAppointByRecordId(String channelCode, String hospitalCode, String recordId) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> params = new HashMap<>(16);
        params.put("channelCode", channelCode);
        params.put("id", recordId);
        Map<String, Object> recordMap = clinicAppointmentRecordDao.findOne(params);
        if (recordMap != null) {
            String method = "send";
            Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
            params.put("appointId", recordMap.get("appointId"));
            params.put("user", recordMap.get("username"));
            params.put("idCard", recordMap.get("idCard"));
            Transfer transfer = new CancelAppointmentTransfer(method, client, "DoCancelAppoint");
            Map<String, Object> resultMap = transfer.transfer(params);
            String executeMessage = (String) resultMap.get("message");
            if (Dialect.getSuccessfulState().equals(resultMap.get(ResponseMessage.RES_CODE))) {
                Map<String, Object> modifyParams = new HashMap<>(16);
                modifyParams.put("channelCode", channelCode);
                modifyParams.put("id", recordMap.get("id"));
                modifyParams.put("state", "1");
                this.clinicAppointmentRecordDao.modify(modifyParams);
                res.putAll(recordMap);
                res.remove("username");
                String categorCode = (String) res.remove("doctorTitleCode");
                String cardNum = (String) res.remove("cardId");
                res.put("categorCode", categorCode);
                res.put("categorName", Dialect.getClinicType(categorCode));
                res.put("cardNum", cardNum);
                res.put("state", "1");
                res.remove("appointFee");
                res.remove("personId");
                res.remove("hospitalCode");
                res.remove("modifyTime");
                for (Map.Entry<String, Object> entry : res.entrySet()) {
                    Object val = entry.getValue();
                    if (val == null) {
                        entry.setValue("");
                    } else if (!(val instanceof Date)) {
                        entry.setValue(val.toString());
                    }
                }
                res.put(ResponseMessage.RES_CODE, "0");
                res.put(ResponseMessage.MESSAGE_IN, "取消成功");
                res.put(ResponseMessage.MESSAGE, "取消成功");
                res.put(ResponseMessage.MESSAGE_OUT, "取消成功");
            } else {
                res.put(ResponseMessage.RES_CODE, "-11");
                res.put(ResponseMessage.MESSAGE_IN, executeMessage);
                res.put(ResponseMessage.MESSAGE, executeMessage);
                res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
            }
        } else {
            res.put(ResponseMessage.RES_CODE, "-3");
            res.put(ResponseMessage.MESSAGE, "未找到" + recordId + "相关记录");
            res.put(ResponseMessage.MESSAGE_IN, "未找到" + recordId + "相关记录");
            res.put(ResponseMessage.MESSAGE_OUT, "未找到" + recordId + "相关记录");
        }
        return res;
    }

    /**
     * 当日挂号数据保存
     *
     * @param channelCode  渠道编码
     * @param hospitalCode 医院编码
     * @param name         姓名
     * @param gender       性别
     * @param age          年龄
     * @param clinicLabel  号表
     * @param regFee       挂号费
     * @param period       时段
     * @param usePersonId  用户使用id
     * @param idCard       身份证号
     * @param patientId    患者索引
     * @param chargeType   费别
     * @param clinicType   号类
     * @param deptCode     科室编码
     * @param doctorCode   医生编码
     * @param doctorName   医生姓名
     * @param cardId       卡id
     * @param cardType     卡类型
     * @return 挂号结果
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> saveRegister(String channelCode, String hospitalCode, String name, String gender, String age, String clinicLabel, String regFee, String period, String usePersonId, String idCard, String patientId, String chargeType, String clinicType, String deptCode, String doctorCode, String doctorName, String cardId, String cardType) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> params = new HashMap<>(16);
        Map<String, Object> resultMap = new HashMap<>(16);
        String method = "send";
        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
        Transfer transfer = new SaveRegisterTransfer(method, client, "SaveRegist");
        params.put("clinicLabel", clinicLabel);
        params.put("name", name);
        params.put("gender", gender);
        params.put("age", age);
        params.put("period", period);
        params.put("username", usePersonId);
        params.put("idCard", idCard);
        params.put("patientId", patientId);
        params.put("chargeType", chargeType);
        params.put("clinicType", Dialect.getClinicType(clinicType));
        params.put("deptCode", deptCode);
        params.put("doctorCode", doctorCode);
        params.put("doctorName", doctorName);
        params.put("cardId", cardId);
        params.put("cardType", cardType);
        resultMap = transfer.transfer(params);
        String executeMessage = (String) resultMap.get("message");
        if (Dialect.getSuccessfulState().equals(resultMap.get(ResponseMessage.RES_CODE))) {
            Map<String, Object> addMap = new HashMap<>(16);
            String id = DataFormatUtils.getTimeStringNoSpace(new Date()) + hospitalCode + channelCode + IdGenerator.getSixRandNum();
            addMap.put("id", id);
            addMap.put("channelCode", channelCode);
            addMap.put("hospitalCode", hospitalCode);
            addMap.put("amount", regFee);
            addMap.put("totalCost", regFee);
            addMap.put("ampm", Dialect.getAmpmCode(period));
            addMap.put("createTime", DataFormatUtils.getTimeString(new Date()));
            addMap.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
            addMap.put("state", "4");
            addMap.put("personId", idCard);
            addMap.put("idCard", idCard);
            addMap.put("name", name);
            addMap.put("phone", usePersonId);
            addMap.put("cardId", cardId);
            addMap.put("cardType", cardType);
            addMap.put("tranNo", resultMap.get("tranNo"));
            addMap.put("patientType", chargeType);
            addMap.put("appointDate", resultMap.get("visitDate"));
            addMap.put("deptCode", deptCode);
            addMap.put("doctorCode", doctorCode);
            addMap.put("doctorTitleCode", clinicType);
            //"3"当日挂号
            addMap.put("appointmentType", "3");
            addMap.put("visitNo", resultMap.get("visitNo"));
            addMap.put("rcptNo", resultMap.get("rcptNo"));
            addMap.put("clinicLabel", clinicLabel);
            addMap.put("username", usePersonId);
            clinicAppointmentRecordDao.add(addMap);
            res.put("recordId", id);
            res.put("channelCode", channelCode);
            res.put("subject", "挂号费");
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "当日挂号数据保存成功");
            res.put(ResponseMessage.MESSAGE, "当日挂号数据保存成功");
            res.put(ResponseMessage.MESSAGE_OUT, "当日挂号数据保存成功");
        } else {
            res.put(ResponseMessage.RES_CODE, "-22");
            res.put(ResponseMessage.MESSAGE_IN, executeMessage);
            res.put(ResponseMessage.MESSAGE, executeMessage);
            res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
        }
        return res;
    }

    /**
     * 预约号生成支付订单
     *
     * @param channelCode
     * @param hospitalCode
     * @param appointmentCode
     * @param userPersonId    挂号用户id
     * @return
     */
    @Override
    public Map<String, Object> generateOrdersForRegister(String channelCode, String hospitalCode, String appointmentCode, String userPersonId) {
        return null;
    }

    /**
     * 挂号支付确认接口(提供给支付平台支付完成之后回调)
     *
     * @param channelCode  渠道编码
     * @param hospitalCode 医院编码
     * @param recordId     挂号ID
     * @param openId       支付用户唯一ID：微信用户唯一ID、支付宝用户唯一ID、银行卡号
     * @param orderId      订单ID
     * @param patientId    患者ID
     * @param userPersonId 用户ID
     * @param orderFee     支付金额
     * @param payTime      支付时间
     * @param payType      支付类别
     * @param tradeNo      交易流水
     * @return
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> payConfirmForRegister(String channelCode, String hospitalCode, String recordId, String openId, String orderId, String patientId, String userPersonId, String orderFee, String payTime, String payType, String tradeNo) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> params = new HashMap<>(16);
        Map<String, Object> daoRes = new HashMap<>(16);
        params.put("channelCode", channelCode);
        params.put("id", recordId);
        daoRes = clinicAppointmentRecordDao.findOne(params);
        if (daoRes != null) {
            Map<String, Object> resMap = new HashMap<>(16);
            String method = "send";
            Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
            Transfer transfer = new PayConfirmForRegistTransfer(method, client, "RegistTranConfirm");
            params.putAll(daoRes);
            params.put("patientId", patientId);
            params.put("orderFee", orderFee);
            params.put("tradeNo", tradeNo);
            params.put("payType", payType);
            resMap = transfer.transfer(params);
            String executeMessage = (String) resMap.get("message");
            if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
                Map<String, Object> daoParams = new HashMap<>(16);
                Map<String, Object> billParams = new HashMap<>(16);
                String tranNo = (String) resMap.get("tranNo");
                res.putAll(resMap);
                res.put(ResponseMessage.RES_CODE, "0");
                res.put(ResponseMessage.MESSAGE_IN, "当日挂号支付确认成功");
                res.put(ResponseMessage.MESSAGE, "当日挂号支付确认成功");
                res.put(ResponseMessage.MESSAGE_OUT, "当日挂号支付确认成功");
                daoParams.put("channelCode", channelCode);
                daoParams.put("tranNo", tranNo);
                daoParams.put("state", "2");
                daoParams.put("id", recordId);
                daoParams.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
                clinicAppointmentRecordDao.modify(daoParams);
                Map<String, Object> findOneRes = clinicAppointmentRecordDao.findOne(daoParams);
                billParams.put("billId", orderId);
                billParams.put("hospitalCode", hospitalCode);
                billParams.put("doctorCode", findOneRes.get("doctorCode"));
                billParams.put("deptCode", findOneRes.get("deptCode"));
                billParams.put("appointmentCode", recordId);
                billParams.put("appointDate", DataFormatUtils.getTimeString((Date) findOneRes.get("appointDate")));
                billParams.put("transactNo", tranNo);
                billParams.put("orderId", findOneRes.get("rcptNo"));
                billParams.put("patientId", patientId);
                billParams.put("visitNo", findOneRes.get("visitNo"));
                billParams.put("prescriptionNum", "");
                billParams.put("channelCode", channelCode);
                billParams.put("personId", findOneRes.get("personId"));
                billParams.put("idCard", findOneRes.get("idCard"));
                billParams.put("personName", findOneRes.get("name"));
                billParams.put("phone", userPersonId);
                billParams.put("username", userPersonId);
                billParams.put("cardType", payType);
                billParams.put("cardNum", openId);
                billParams.put("patientType", findOneRes.get("patientType"));
                billParams.put("totalCost", findOneRes.get("totalCost"));
                billParams.put("tradeNo", tradeNo);
                billParams.put("cost", orderFee);
                billParams.put("insuranceAmount", findOneRes.get("insurPay"));
                billParams.put("personalAmount", findOneRes.get("insurAccountPay"));
                billParams.put("otherAmount", orderFee);
                billParams.put("payWay", payType);
                billParams.put("visitDate", DataFormatUtils.getTimeString((Date) findOneRes.get("appointDate")));
                billParams.put("createTime", DataFormatUtils.getTimeString(new Date()));
                billParams.put("payTime", payTime);
                billParams.put("billTypeCode", "1");
                billParams.put("payType", payType);
                billParams.put("state", "0");
                billingRecordDao.add(billParams);
            } else {
                res.put(ResponseMessage.RES_CODE, "-23");
                res.put(ResponseMessage.MESSAGE_IN, executeMessage);
                res.put(ResponseMessage.MESSAGE, executeMessage);
                res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
            }
        } else {
            res.put(ResponseMessage.RES_CODE, "-3");
            res.put(ResponseMessage.MESSAGE, "未找到" + recordId + "相关记录");
            res.put(ResponseMessage.MESSAGE_IN, "未找到" + recordId + "相关记录");
            res.put(ResponseMessage.MESSAGE_OUT, "未找到" + recordId + "相关记录");
        }
        return res;
    }

    /**
     * 退号
     *
     * @param channelCode     渠道编码
     * @param hospitalCode    医院编码
     * @param idCard          身份证号
     * @param appointmentCode 预约id(院内)
     * @param refund          是否退费
     * @param desc            退号描述
     * @return 退号结果
     */
    @Override
    public Map<String, Object> retreat(String channelCode, String hospitalCode, String idCard, String appointmentCode, String refund, String desc) {
        return null;
    }

    /**
     * 诊间结算列表查询
     *
     * @param channelCode   渠道编码
     * @param hospitalCode  医院编码
     * @param recordId      挂号序列
     * @param patientId     患者ID
     * @param source        挂号来源
     * @param user          用户名
     * @param payState      支付状态
     * @param clinicPayType 诊间结算类型
     * @return
     */
    @Override
    public Map<String, Object> loadClinicChargeList(String channelCode, String hospitalCode, String recordId, String patientId, String source, String user, String payState, String clinicPayType) throws Exception {
        Map<String, Object> res = new LinkedHashMap<>();
        Map<String, Object> params = new HashMap<>(16);
        params.put("id", recordId);
        Map<String, Object> resDaoMap = clinicAppointmentRecordDao.findOne(params);
        if (resDaoMap != null) {
            params.put("patientId", patientId);
            params.put("idCard", resDaoMap.get("idCard"));
            params.put("appointDate", resDaoMap.get("appointDate"));
            params.put("tranNo", resDaoMap.get("tranNo"));
            params.put("visitNo", resDaoMap.get("visitNo"));
            Map<String, Object> resMap = new HashMap<>(16);
            String method = "send";
            Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
            Transfer transfer = new LoadClinicChargeListTransfer(method, client, "GetCharge");
            resMap = transfer.transfer(params);
            String executeMessage = (String) resMap.get("message");
            if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
                res.put("recordId", recordId);
                res.put("patientId", patientId);
                res.put("appNoList", resMap.get("appNoList"));
                res.put(ResponseMessage.RES_CODE, "0");
                res.put(ResponseMessage.MESSAGE_IN, "查询诊间待缴费列表成功");
                res.put(ResponseMessage.MESSAGE, "查询诊间待缴费列表成功");
                res.put(ResponseMessage.MESSAGE_OUT, "查询诊间待缴费列表成功");
            } else {
                res.put(ResponseMessage.RES_CODE, "-26");
                res.put(ResponseMessage.MESSAGE_IN, executeMessage);
                res.put(ResponseMessage.MESSAGE, executeMessage);
                res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
            }
        } else {
            res.put(ResponseMessage.RES_CODE, "-3");
            res.put(ResponseMessage.MESSAGE, "未找到 recordId 相关记录");
            res.put(ResponseMessage.MESSAGE_IN, "未找到 recordId 相关记录");
            res.put(ResponseMessage.MESSAGE_OUT, "未找到 recordId 相关记录");
        }

        return res;
    }

    /**
     * 诊间待缴费详情查询
     *
     * @param channelCode   渠道编码
     * @param hospitalCode  医院编码
     * @param recordId      挂号序列
     * @param patientId     患者ID
     * @param paySeq        处方号
     * @param source        挂号来源
     * @param user          用户名
     * @param payState      支付状态
     * @param clinicPayType 诊间结算类型
     * @return
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> loadClinicChargeDetails(String channelCode, String hospitalCode, String recordId, String patientId, String paySeq, String source, String user, String payState, String clinicPayType) throws Exception {
        Map<String, Object> res = new LinkedHashMap<>();
        Map<String, Object> params = new HashMap<>(16);
        params.put("id", recordId);
        Map<String, Object> resDaoMap = clinicAppointmentRecordDao.findOne(params);
        if (resDaoMap != null) {
            params.put("patientId", patientId);
            params.put("idCard", resDaoMap.get("idCard"));
            params.put("appointDate", resDaoMap.get("appointDate"));
            params.put("tranNo", resDaoMap.get("tranNo"));
            params.put("visitNo", resDaoMap.get("visitNo"));
            params.put("paySeq", paySeq);
            Map<String, Object> resMap = new HashMap<>(16);
            String method = "send";
            Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
            Transfer transfer = new LoadClinicChargeDetailsTransfer(method, client, "GetCharge");
            resMap = transfer.transfer(params);
            String executeMessage = (String) resMap.get("message");
            if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
                List<Map<String, Object>> chargeDetailsList = (List<Map<String, Object>>) resMap.get("chargeDetailsList");
                res.put("recordId", recordId);
                res.put("patientId", patientId);
                res.put("idCard", resDaoMap.get("idCard"));
                res.put("name", resDaoMap.get("name"));
                res.put("cardId", resDaoMap.get("cardId"));
                res.put("cardType", "");
                res.put("visitNo", resDaoMap.get("visitNo"));
                res.put("paySeq", paySeq);
                res.put("payState", "0");
                res.put("visitNo", resDaoMap.get("visitNo"));
                res.put("totalCost", resMap.get("totalCost"));
                res.put("chargeDetailsList", chargeDetailsList);
                res.put("hospitalName", "天津市胸科医院");
                Map<String, Object> daoParams = new HashMap<>(16);
                daoParams.put("paySeq", paySeq);
                //"clinicChargeStatus":"0" 未收费
                daoParams.put("clinicChargeStatus", "0");
                clinicChargeDetailsRecordDao.deleteByPaySeq(daoParams);
                for (Map<String, Object> el : chargeDetailsList) {
                    List<Map<String, Object>> costList = (List<Map<String, Object>>) el.get("costList");
                    for (Map<String, Object> subel : costList) {
                        Map<String, Object> addParamas = new HashMap<>(16);
                        addParamas.put("clinicCostItemId", subel.get("clinicCostItemNo"));
                        addParamas.put("hospitalCode", hospitalCode);
                        addParamas.put("channelCode", channelCode);
                        addParamas.put("userName", user);
                        addParamas.put("recordId", recordId);
                        addParamas.put("paySeq", paySeq);
                        addParamas.put("costs", subel.get("costs"));
                        addParamas.put("parentName", subel.get("parentName"));
                        addParamas.put("charges", subel.get("charges"));
                        addParamas.put("inputDateTime", (String) subel.get("inputDateTime"));
                        addParamas.put("units", subel.get("units"));
                        addParamas.put("usages", subel.get("usage"));
                        addParamas.put("amount", subel.get("amount"));
                        addParamas.put("itemName", subel.get("itemName"));
                        addParamas.put("itemCode", subel.get("itemCode"));
                        addParamas.put("reqId", subel.get("reqId"));
                        addParamas.put("reqClass", subel.get("reqClass"));
                        addParamas.put("doctorInsurType", subel.get("doctorInsurType"));
                        addParamas.put("clinicId", subel.get("clinicId"));
                        addParamas.put("orderedDoctorName", subel.get("orderedDoctor"));
                        addParamas.put("orderedDeptCode", subel.get("orderedDeptCode"));
                        addParamas.put("executionDeptCode", subel.get("executionDeptCode"));
                        addParamas.put("executionDeptName", subel.get("deptName"));
                        addParamas.put("patientId", patientId);
                        addParamas.put("itemSpec", subel.get("itemSpec"));
                        addParamas.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
                        addParamas.put("executionStatus", "0");
                        addParamas.put("clinicChargeStatus", "0");
                        clinicChargeDetailsRecordDao.add(addParamas);
                    }
                }
                res.put(ResponseMessage.RES_CODE, "0");
                res.put(ResponseMessage.MESSAGE_IN, "查询诊间待缴费详情成功");
                res.put(ResponseMessage.MESSAGE, "查询诊间待缴费详情成功");
                res.put(ResponseMessage.MESSAGE_OUT, "查询诊间待缴费详情成功");
            } else {
                res.put(ResponseMessage.RES_CODE, "-25");
                res.put(ResponseMessage.MESSAGE_IN, executeMessage);
                res.put(ResponseMessage.MESSAGE, executeMessage);
                res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
            }
        } else {
            res.put(ResponseMessage.RES_CODE, "-3");
            res.put(ResponseMessage.MESSAGE, "未找到 recordId 为" + recordId + "的相关记录");
            res.put(ResponseMessage.MESSAGE_IN, "未找到 recordId 为" + recordId + "的相关记录");
            res.put(ResponseMessage.MESSAGE_OUT, "未找到 recordId 为" + recordId + "的相关记录");
        }

        return res;
    }

    /**
     * 诊间结算数据保存
     *
     * @param channelCode  渠道编码
     * @param hospitalCode 医院编码
     * @param userName     操作用户
     * @param recordId     挂号序列
     * @param idCard       身份证号
     * @param resDate      挂号日期
     * @param transactNo   合同号
     * @param patientId    院内患者ID
     * @param visitNo      就诊号
     * @param paySeq       支付序号
     * @param cardType     就诊卡类型
     * @param cardNumber   就诊卡号
     * @return
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> saveclinicChargeData(String channelCode, String hospitalCode, String userName, String recordId, String idCard, String resDate, String transactNo, String patientId, String visitNo, String paySeq, String cardType, String cardNumber) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> resMap = new HashMap<>(16);
        Map<String, Object> findparams = new HashMap<>(16);
        findparams.put("paySeq", paySeq);
        findparams.put("channelCode", channelCode);
        findparams.put("hospitalCode", hospitalCode);
        findparams.put("clinicChargeStatus", "0");
        List<Map<String, Object>> costList = clinicChargeDetailsRecordDao.find(findparams);
        if (costList.size() != 0) {
            String method = "send";
            Map<String, Object> params = new HashMap<>(16);
            params.put("paySeq", paySeq);
            params.put("idCard", idCard);
            params.put("resDate", resDate);
            params.put("transactNo", transactNo);
            params.put("patientId", patientId);
            params.put("visitNo", visitNo);
            params.put("costList", costList);
            Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
            Transfer transfer = new SaveclinicChargeDataTransfer(method, client, "SaveCharge");
            resMap = transfer.transfer(params);
            String executeMessage = (String) resMap.get("message");
            if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
                Map<String, Object> saveDaoParams = new HashMap<>(16);
                saveDaoParams.put("paySeq", paySeq);
                saveDaoParams.put("idCard", idCard);
                saveDaoParams.put("hospitalCode", hospitalCode);
                saveDaoParams.put("clinicChargeStatus", 2);
                saveDaoParams.put("channelCode", channelCode);
                saveDaoParams.put("userName", userName);
                saveDaoParams.put("recordId", recordId);
                saveDaoParams.put("patientId", patientId);
                saveDaoParams.put("insurPay", resMap.get("insurPay"));
                saveDaoParams.put("insurAccountPay", resMap.get("accountPay"));
                saveDaoParams.put("ownPay", resMap.get("ownPay"));
                saveDaoParams.put("rcptNo", resMap.get("rcptNo"));
                saveDaoParams.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
                saveDaoParams.put("tranNo", resMap.get("tranNo"));
                saveDaoParams.put("idCard", idCard);
                clinicChargeRecordDao.duplicateAdd(saveDaoParams);
                res.putAll(resMap);
                res.remove("rcptNo");
                res.put("recordId ", recordId);
                res.put("patientId", patientId);
                res.put(ResponseMessage.RES_CODE, "0");
                res.put(ResponseMessage.MESSAGE_IN, "缴费数据保存成功");
                res.put(ResponseMessage.MESSAGE, "缴费数据保存成功");
                res.put(ResponseMessage.MESSAGE_OUT, "缴费数据保存成功");
            } else {
                res.put(ResponseMessage.RES_CODE, "-28");
                res.put(ResponseMessage.MESSAGE_IN, executeMessage);
                res.put(ResponseMessage.MESSAGE, executeMessage);
                res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
            }
        } else {
            res.put(ResponseMessage.RES_CODE, "-3");
            res.put(ResponseMessage.MESSAGE, "未找到 paySeq 的相关记录");
            res.put(ResponseMessage.MESSAGE_IN, "未找到 paySeq 的相关记录");
            res.put(ResponseMessage.MESSAGE_OUT, "未找到 paySeq 的相关记录");
        }
        return res;
    }

    /**
     * 诊间结算支付确认
     *
     * @param channelCode  渠道编码
     * @param hospitalCode 医院编码
     * @param paySeq       支付序号
     * @param openId       支付用户唯一ID：微信用户唯一ID、支付宝用户唯一ID、银行卡号
     * @param orderId      订单ID
     * @param patientId    患者ID
     * @param userPersonId 用户ID
     * @param orderFee     支付金额
     * @param payTime      支付时间
     * @param payType      支付类别
     * @param tradeNo      交易流水
     * @return
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> payConfirmForClinicCharge(String channelCode, String hospitalCode, String paySeq, String openId, String orderId, String patientId, String userPersonId, String orderFee, String payTime, String payType, String tradeNo) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> params = new HashMap<>(16);
        Map<String, Object> daoRes = new HashMap<>(16);
        params.put("hospitalCode", hospitalCode);
        params.put("paySeq", paySeq);
        daoRes = clinicChargeRecordDao.findOne(params);
        if (daoRes != null) {
            params.put("id", daoRes.get("recordId"));
            Map<String, Object> registRecord = clinicAppointmentRecordDao.findOne(params);
            if (registRecord != null) {
                Map<String, Object> resMap = new HashMap<>(16);
                String method = "send";
                Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
                Transfer transfer = new PayConfirmForClinicChargeTransfer(method, client, "ChargeTranConfirm");
                params.put("idCard", registRecord.get("idCard"));
                params.put("patientId", patientId);
                params.put("visitNo", registRecord.get("visitNo"));
                params.put("appointDate", registRecord.get("appointDate"));
                params.put("rcptNo", daoRes.get("rcptNo"));
                params.put("tranNo", daoRes.get("tranNo"));
                params.put("tradeNo", tradeNo);
                params.put("patientId", patientId);
                params.put("orderFee", orderFee);
                params.put("payType", payType);
                resMap = transfer.transfer(params);
                String executeMessage = (String) resMap.get("message");
                if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
                    Map<String, Object> daoParams = new HashMap<>(16);
                    Map<String, Object> billParams = new HashMap<>(16);
                    String tranNo = (String) resMap.get("tranNo");
                    res.putAll(resMap);
                    res.put(ResponseMessage.RES_CODE, "0");
                    res.put(ResponseMessage.MESSAGE_IN, "诊间缴费支付确认成功");
                    res.put(ResponseMessage.MESSAGE, "诊间缴费支付确认成功");
                    res.put(ResponseMessage.MESSAGE_OUT, "诊间缴费支付确认成功");
                    daoParams.put("paySeq", paySeq);
                    daoParams.put("hospitalCode", hospitalCode);
                    daoParams.put("clinicChargeStatus", "1");
                    daoParams.put("tranNo", resMap.get("tranNo"));
                    daoParams.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
                    clinicChargeRecordDao.modifyByPaySeq(daoParams);
                    daoParams.put("id", daoRes.get("recordId"));
                    Map<String, Object> findOneRes = clinicAppointmentRecordDao.findOne(daoParams);
                    billParams.put("billId", orderId);
                    billParams.put("hospitalCode", hospitalCode);
                    billParams.put("doctorCode", findOneRes.get("doctorCode"));
                    billParams.put("deptCode", findOneRes.get("deptCode"));
                    billParams.put("appointmentCode", daoRes.get("recordId"));
                    billParams.put("appointDate", DataFormatUtils.getTimeString((Date) findOneRes.get("appointDate")));
                    billParams.put("transactNo", resMap.get("tranNo"));
                    billParams.put("orderId", daoRes.get("rcptNo"));
                    billParams.put("patientId", patientId);
                    billParams.put("visitNo", findOneRes.get("visitNo"));
                    billParams.put("prescriptionNum", "");
                    billParams.put("channelCode", channelCode);
                    billParams.put("personId", findOneRes.get("personId"));
                    billParams.put("idCard", findOneRes.get("idCard"));
                    billParams.put("personName", findOneRes.get("name"));
                    billParams.put("phone", userPersonId);
                    billParams.put("username", userPersonId);
                    billParams.put("cardType", payType);
                    billParams.put("cardNum", openId);
                    billParams.put("patientType", findOneRes.get("patientType"));
                    billParams.put("totalCost", findOneRes.get("totalCost"));
                    billParams.put("tradeNo", tradeNo);
                    billParams.put("cost", orderFee);
                    billParams.put("insuranceAmount", findOneRes.get("insurPay"));
                    billParams.put("personalAmount", findOneRes.get("insurAccountPay"));
                    billParams.put("otherAmount", orderFee);
                    billParams.put("payWay", payType);
                    billParams.put("visitDate", DataFormatUtils.getTimeString((Date) findOneRes.get("appointDate")));
                    billParams.put("createTime", DataFormatUtils.getTimeString(new Date()));
                    billParams.put("payTime", payTime);
                    billParams.put("billTypeCode", "1");
                    billParams.put("payType", payType);
                    billParams.put("state", "0");
                    billingRecordDao.add(billParams);
                } else {
                    res.put(ResponseMessage.RES_CODE, "-23");
                    res.put(ResponseMessage.MESSAGE_IN, executeMessage);
                    res.put(ResponseMessage.MESSAGE, executeMessage);
                    res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
                }
            } else {
                res.put(ResponseMessage.RES_CODE, "-3");
                res.put(ResponseMessage.MESSAGE, "未找到 recordId 相关记录");
                res.put(ResponseMessage.MESSAGE_IN, "未找到 recordId 相关记录");
                res.put(ResponseMessage.MESSAGE_OUT, "未找到 recordId 相关记录");
            }
        } else {
            res.put(ResponseMessage.RES_CODE, "-3");
            res.put(ResponseMessage.MESSAGE, "未找到 paySeq 相关记录");
            res.put(ResponseMessage.MESSAGE_IN, "未找到 paySeq 相关记录");
            res.put(ResponseMessage.MESSAGE_OUT, "未找到 paySeq 相关记录");
        }
        return res;
    }

    /**
     * 诊间结算支付撤销
     *
     * @param channelCode  渠道编码
     * @param hospitalCode 医院编码
     * @param recordId     挂号序列
     * @param patientId    患者ID
     * @param paySeq       支付序号
     * @return
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> canceleClinicChargePayment(String channelCode, String hospitalCode, String recordId, String patientId, String paySeq) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        String method = "send";
        Map<String, Object> params = new HashMap<>(16);
        params.put("channelCode", channelCode);
        params.put("id", recordId);
        Map<String, Object> recordMap = clinicAppointmentRecordDao.findOne(params);
        if (recordMap != null) {
            Map<String, Object> subMap = new HashMap<>(16);
            subMap.put("paySeq", paySeq);
            subMap.put("hospitalCode", hospitalCode);
            Map<String, Object> subMapRes = clinicChargeRecordDao.findOne(subMap);
            if (subMapRes != null) {
                recordMap.put("patientId", patientId);
                recordMap.put("rcptNo", subMapRes.get("rcptNo"));
                Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
                Transfer transfer = new CanceleClinicChargePaymentTransfer(method, client, "TranCancel");
                Map<String, Object> resMap = transfer.transfer(recordMap);
                if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
                    recordMap.remove("rcptNo");
                    recordMap.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
                    recordMap.put("clinicChargeStatus", 0);
                    recordMap.put("paySeq", paySeq);
                    recordMap.put("hospitalCode", hospitalCode);
                    clinicChargeRecordDao.modifyByPaySeq(recordMap);
                    res.putAll(resMap);
                    res.put(ResponseMessage.RES_CODE, "0");
                    res.put(ResponseMessage.MESSAGE_IN, "诊间支付交易撤销成功");
                    res.put(ResponseMessage.MESSAGE, "诊间支付交易撤销成功");
                    res.put(ResponseMessage.MESSAGE_OUT, "诊间支付交易撤销成功");
                } else {
                    String executeMessage = (String) resMap.get("message");
                    if ("该笔已正常缴费，不能进行撤销!".equals(executeMessage)) {
                        recordMap.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
                        recordMap.put("clinicChargeStatus", 1);
                        recordMap.put("paySeq", paySeq);
                        recordMap.put("hospitalCode", hospitalCode);
                        clinicChargeRecordDao.modifyByPaySeq(recordMap);
                    }
                    res.put(ResponseMessage.RES_CODE, "0");
                    res.put(ResponseMessage.MESSAGE_IN, executeMessage);
                    res.put(ResponseMessage.MESSAGE, executeMessage);
                    res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
                }
            } else {
                res.put(ResponseMessage.RES_CODE, "-3");
                res.put(ResponseMessage.MESSAGE, "未找到 paySeq 相关记录");
                res.put(ResponseMessage.MESSAGE_IN, "未找到 paySeq 相关记录");
                res.put(ResponseMessage.MESSAGE_OUT, "未找到 paySeq 相关记录");
            }
        } else {
            res.put(ResponseMessage.RES_CODE, "-3");
            res.put(ResponseMessage.MESSAGE, "未找到 recordId 相关记录");
            res.put(ResponseMessage.MESSAGE_IN, "未找到 recordId 相关记录");
            res.put(ResponseMessage.MESSAGE_OUT, "未找到 recordId 相关记录");
        }

        return res;
    }


    /**
     * 获取挂号列表
     *
     * @param channelCode  渠道编码
     * @param hospitalCode 医院编码
     * @param startTime    开始时间
     * @param endTime      结束时间
     * @param idCard       身份证号
     * @return 查询结果
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> loadAllRegistRecords(String channelCode, String hospitalCode, String startTime, String endTime, String idCard) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        /*固定格式*/
        String method = "send";
        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
        Transfer transfer = new LoadAllRegistAndAppointRecordsTransfer(method, client, "GetRegistAndAppoint");
        /*固定格式*/
        Map<String, Object> params = new HashMap<>(16);
        params.put("startTime", startTime);
        params.put("endTime", endTime);
        params.put("idCard", idCard);
        Map<String, Object> resultMap = transfer.transfer(params);
        if (Dialect.getSuccessfulState().equals(resultMap.get(ResponseMessage.RES_CODE))) {
            List<Map<String, Object>> records = (List<Map<String, Object>>) resultMap.get("records");
            if (records != null && records.size() > 0) {
                for (Map<String, Object> subMap : records) {
                    subMap.put("stateName", Dialect.getAppointStatusName((String) subMap.get("state")));
                    Map<String, Object> paramsMap = new HashMap<>(16);
                    paramsMap.put("appointId", subMap.get("appointId"));
                    paramsMap.put("channelCode", channelCode);
                    paramsMap.put("hospitalCode", hospitalCode);
                    paramsMap.put("rcptNo", subMap.get("rcptNo"));
                    paramsMap.put("idCard", idCard);
                    Map<String, Object> daoResMap = clinicAppointmentRecordDao.findOne(paramsMap);
                    if (daoResMap != null) {
                        Map<String, Object> resMap = new HashMap<>(16);
                        resMap.put("id", daoResMap.get("id"));
                        Map<String, Object> ResMap = clinicAppointmentRecordDao.findOne(resMap);
                        if (ResMap != null) {
                            //                    subMap.put("recordId", daoResMap.get("id"));
                            if (!(subMap.get("state").equals(ResMap.get("state")))) {
                                resMap.put("hisClinicAppointsId", subMap.get("hisClinicAppointsId"));
                                resMap.put("state", subMap.get("state"));
                                resMap.put("clinicFee", subMap.get("regFee"));
                                resMap.put("totalCost", subMap.get("regFee"));
                                resMap.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
                                resMap.put("innerSort", subMap.get("innerSort"));
                                resMap.put("queueNum", subMap.get("queueNum"));
                                resMap.put("insurVisitId", subMap.get("insurVisitId"));
                                resMap.put("insurPay", subMap.get("insurPay"));
                                resMap.put("insurAccountPay", subMap.get("accountPay"));
                                resMap.put("ownPay", subMap.get("ownPay"));
                                resMap.put("rcptNo", subMap.get("rcptNo"));
                                resMap.put("visitNo", subMap.get("visitNo"));
                                resMap.put("mtType", subMap.get("mtType"));
                                resMap.put("insuranceType", subMap.get("insuranceType"));
                                resMap.put("payType", subMap.get("payType"));
                            } else {
                                resMap.put("hisClinicAppointsId", subMap.get("hisClinicAppointsId"));
                                resMap.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
                                resMap.put("state", subMap.get("state"));
                                resMap.put("visitNo", subMap.get("visitNo"));
                            }
                            clinicAppointmentRecordDao.modify(resMap);
                            subMap.put("recordId", ResMap.get("id"));
                        }
                    } else {
                        String id = DataFormatUtils.getTimeStringNoSpace(new Date()) + hospitalCode + channelCode + IdGenerator.getSixRandNum();
                        Map<String, Object> el = new HashMap<>();
                        el.put("id", id);
                        el.put("channelCode", channelCode);
                        el.put("hospitalCode", hospitalCode);
                        el.put("user", subMap.get("orderStatus"));
                        el.put("personId", idCard);
                        el.put("idCard", idCard);
                        el.put("name", subMap.get("name"));
                        el.put("phone", subMap.get("phone"));
                        el.put("appointId", subMap.get("appointId"));
                        el.put("clinicLabel", subMap.get("clinicLabel"));
                        el.put("patientType", subMap.get("patientType"));
                        el.put("appointDate", subMap.get("appointDate"));
                        el.put("transactNo", subMap.get("transactNo"));
                        el.put("period", subMap.get("period"));
                        el.put("ampm", subMap.get("ampm"));
                        el.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
                        el.put("deptCode", subMap.get("deptId"));
                        el.put("doctorCode", subMap.get("docId"));
                        el.put("doctorTitleCode", subMap.get("categorCode"));
                        el.put("period", subMap.get("period"));
                        el.put("innerSort", subMap.get("innerSort"));
                        el.put("queueNum", subMap.get("queueNum"));
                        el.put("state", subMap.get("state"));
                        el.put("appointmentType", subMap.get("appointmentType"));
                        el.put("clinicFee", subMap.get("regFee"));
                        el.put("otherFee", subMap.get("otherFee"));
                        el.put("deptAddress", "");
                        el.put("totalCost", subMap.get("regFee"));
                        el.put("insurVisitId", subMap.get("insurVisitId"));
                        el.put("insurPay", subMap.get("insurPay"));
                        el.put("insurAccountPay", subMap.get("accountPay"));
                        el.put("ownPay", subMap.get("ownPay"));
                        el.put("rcptNo", subMap.get("rcptNo"));
                        el.put("visitNo", subMap.get("visitNo"));
                        el.put("cardId", subMap.get("cardNum"));
                        el.put("mtType", subMap.get("mtType"));
                        el.put("insuranceType", subMap.get("insuranceType"));
                        el.put("payType", subMap.get("payType"));
                        el.put("doctorName", subMap.get("doctorName"));
                        el.put("hisClinicAppointsId", subMap.get("hisClinicAppointsId"));
                        clinicAppointmentRecordDao.add(el);
                        subMap.put("recordId", id);
                    }
                }

            }
            res.putAll(resultMap);
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "查询挂号记录成功");
            res.put(ResponseMessage.MESSAGE, "查询挂号记录成功");
            res.put(ResponseMessage.MESSAGE_OUT, "查询挂号记录成功");
        } else {
            String executeMessage = (String) resultMap.get("message");
            res.put(ResponseMessage.RES_CODE, "-13");
            res.put(ResponseMessage.MESSAGE_IN, executeMessage);
            res.put(ResponseMessage.MESSAGE, executeMessage);
            res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
        }

        return res;
    }

    /**
     * 诊间退费
     *
     * @param idCard     身份证号
     * @param transactNo 交易号（银行或支付宝的订单流水号）
     * @param describe   退费说明
     * @param money      退费金额
     * @param createTime 退费时间
     * @param cardNum    卡号
     * @param rcptNo     交易流水
     * @return 退费结果
     */
    @Override
    public Map<String, Object> clinicChargeReturn(String idCard, String transactNo, String describe, String money, String createTime, String cardNum, String rcptNo) {
        return null;
    }

    @Override
    public Map<String, Object> sendVerificationCode(String channelCode, String type, String phone) throws Exception {
        Map<String, Object> res = AuthHelper.sendLoginVerificationCode(type, cleverClinicContext.getContextConfig().getAuthUrl(), channelCode, phone);
        return res;
    }

    /**
     * 提取创建患者数据
     *
     * @param idCard 身份证号
     * @return
     */
    @Override
    public Map<String, Object> extractCreationPatient(String channelCode, String hospitalCode, String idCard) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> params = new HashMap<>(16);
        params.put("idCard", idCard);
        params.put("personId", idCard);
        Map<String, Object> resMapPerson = personDao.findOne(params);
        if (resMapPerson != null) {
            String method = "send";
            Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
            Transfer transfer = new ExtractCreationPatientTransfer(method, client, "EstablishPatient");
            String name = (String) resMapPerson.get("name");
            GetInformationByIdCardUtil getInformationByIdCardUtil = new GetInformationByIdCardUtil();
            String age = getInformationByIdCardUtil.getAgeByIdCard(idCard);
            String dateOfBirth = DataFormatUtils.getSimpleTimeString((Date) resMapPerson.get("dateOfBirth"));
            String gender = (String) resMapPerson.get("sex");
            String phone = (String) resMapPerson.get("phone");
            //patientType  自费时为D；
            String patientType = "D";
            params.put("name", name);
            params.put("age", age);
            params.put("dateOfBirth", dateOfBirth);
            params.put("sex", gender);
            params.put("phone", phone);
            params.put("patientType", patientType);
            Map<String, Object> resMap = transfer.transfer(params);
            if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
                if (!(resMap.get("patientId") == null || "".equals(resMap.get("patientId")))) {
                    res.putAll(resMap);
                    res.put("name", name);
                    res.put("age", age);
                    res.put("dateOfBirth", dateOfBirth);
                    res.put("sex", gender);
                    res.put("phone", phone);
                    res.put("patientType", patientType);
                    res.put(ResponseMessage.RES_CODE, "0");
                    res.put(ResponseMessage.MESSAGE_IN, "提取创建患者信息成功");
                    res.put(ResponseMessage.MESSAGE, "提取创建患者信息成功");
                    res.put(ResponseMessage.MESSAGE_OUT, "提取创建患者信息成功");
                } else {
                    res.putAll(resMap);
                    res.put(ResponseMessage.RES_CODE, "-18");
                    res.put(ResponseMessage.MESSAGE_IN, "提取创建患者信息失败");
                    res.put(ResponseMessage.MESSAGE, "提取创建患者信息失败");
                    res.put(ResponseMessage.MESSAGE_OUT, "提取创建患者信息失败");
                }
            } else {
                String executeMessage = (String) resMap.get("message");
                res.put(ResponseMessage.RES_CODE, "-14");
                res.put(ResponseMessage.MESSAGE_IN, executeMessage);
                res.put(ResponseMessage.MESSAGE, executeMessage);
                res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
            }
        } else {
            res.put(ResponseMessage.RES_CODE, "-17");
            res.put(ResponseMessage.MESSAGE_IN, "平台未查询到患者信息");
            res.put(ResponseMessage.MESSAGE, "平台未查询到患者信息");
            res.put(ResponseMessage.MESSAGE_OUT, "平台未查询到患者信息");
        }
        return res;
    }

    /**
     * 提取患者数据
     *
     * @param idCard
     * @return
     */
    @Override
    public Map<String, Object> queryPatientInfo(String channelCode, String hospitalCode, String idCard) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> params = new HashMap<>(16);
        params.put("idCard", idCard);
        String method = "send";
        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
        Transfer transfer = new QueryPatientInfoTransfer(method, client, "GetPatient");
        Map<String, Object> resMap = transfer.transfer(params);
        if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
            res.putAll(resMap);
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "获取患者信息成功");
            res.put(ResponseMessage.MESSAGE, "获取患者信息成功");
            res.put(ResponseMessage.MESSAGE_OUT, "获取患者信息成功");
        } else {
            String executeMessage = (String) resMap.get("message");
            res.put(ResponseMessage.RES_CODE, "-20");
            res.put(ResponseMessage.MESSAGE_IN, executeMessage);
            res.put(ResponseMessage.MESSAGE, executeMessage);
            res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
        }
        return res;
    }


    /**
     * 获取当日挂号详情
     *
     * @param channelCode
     * @param hospitalCode
     * @param id           唯一ID
     * @return
     */
    @Override
    public Map<String, Object> queryRegistDetails(String channelCode, String hospitalCode, String id) throws Exception {
        Map<String, Object> res = new HashMap<>();
        String method = "send";
        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
        Transfer transfer = new QueryRegistDetailsTransfer(method, client, "GetRegistNew");
        String rcptNo = "";
        Map<String, Object> params = new HashMap<>(16);
        params.put("rcptNo", rcptNo);
        Map<String, Object> resultMap = transfer.transfer(params);

        if (Dialect.getSuccessfulState().equals(resultMap.get(ResponseMessage.RES_CODE))) {
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "查询挂号详情成功");
            res.put(ResponseMessage.MESSAGE, "查询挂号成功");
            res.put(ResponseMessage.MESSAGE_OUT, "查询挂号详情成功");
            res.putAll(resultMap);
        } else {
            res.put(ResponseMessage.RES_CODE, "-15");
            res.put(ResponseMessage.MESSAGE, "未找到相关记录");
            res.put(ResponseMessage.MESSAGE_IN, "未找到相关记录");
            res.put(ResponseMessage.MESSAGE_OUT, "未找到相关记录");
        }

        return res;
    }

    /**
     * 获取预约挂号详情
     *
     * @param channelCode
     * @param hospitalCode
     * @param id           唯一ID
     * @return
     */
    @Override
    public Map<String, Object> queryAppointDetails(String channelCode, String hospitalCode, String id) throws Exception {
        Map<String, Object> res = new HashMap<>();
        String method = "send";
        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
        Transfer transfer = new QueryAppointDetailsTransfer(method, client, "GetAppointMessageById");
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.YEAR, -1);
        String startDate = DataFormatUtils.getSimpleTimeString(calendar.getTime());
        calendar.add(Calendar.YEAR, 1);
        calendar.add(Calendar.DAY_OF_YEAR, 20);
        String endDate = DataFormatUtils.getSimpleTimeString(calendar.getTime());
        Map<String, Object> daoParams = new HashMap<>();
        daoParams.put("id", id);
        String appointId = (String) clinicAppointmentRecordDao.findOne(daoParams).get("appointId");
        Map<String, Object> params = new HashMap<>();
        params.put("appointId", appointId);
        params.put("startDate", startDate);
        params.put("endDate", endDate);
        Map<String, Object> resultMap = transfer.transfer(params);

        if (Dialect.getSuccessfulState().equals(resultMap.get(ResponseMessage.RES_CODE))) {
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "查询预约挂号详情成功");
            res.put(ResponseMessage.MESSAGE, "查询成功");
            res.put(ResponseMessage.MESSAGE_OUT, "查询预约挂号详情成功");
            res.putAll(resultMap);
        } else {
            String executeMessage = (String) resultMap.get("message");
            res.put(ResponseMessage.RES_CODE, "-19");
            res.put(ResponseMessage.MESSAGE_IN, executeMessage);
            res.put(ResponseMessage.MESSAGE, executeMessage);
            res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
        }

        return res;
    }


    @Deprecated
    @Override
    public Map<String, Object> loadingRegistDetails(String id) {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> params = new HashMap<>(16);
        params.put("id", id);
        Map<String, Object> clinicRecord = clinicAppointmentRecordDao.findOne(params);
        if (clinicRecord == null) {
            res.put(ResponseMessage.RES_CODE, "-3");
            res.put(ResponseMessage.MESSAGE, "未找到相关记录");
            res.put(ResponseMessage.MESSAGE_IN, "未找到相关记录");
            res.put(ResponseMessage.MESSAGE_OUT, "未找到相关记录");
        } else {
//            String state
        }
        return params;
    }

    @Override
    public Map<String, Object> queryRegistAndAppointDetail(String channelCode, String hospitalCode, String recordId) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> params = new HashMap<>(16);
        params.put("channelCode", channelCode);
        params.put("id", recordId);
//        String ampm ="无";
        Map<String, Object> recordMap = clinicAppointmentRecordDao.findOne(params);
        if (recordMap != null) {
            res.putAll(recordMap);
            res.remove("username");
            String categorCode = (String) res.remove("doctorTitleCode");
            String cardNum = (String) res.remove("cardId");
            String ampm = (String) res.remove("ampm");
            res.put("categorCode", categorCode);
            res.put("categorName", Dialect.getClinicType(categorCode));
            res.put("cardNum", cardNum);
            res.put("ampm", ampm);
            res.put("ampmName", Dialect.getAmpmName(ampm));
            res.put("stateName", Dialect.getAppointStatusName((String) recordMap.get("state")));
            res.remove("appointFee");
            res.remove("personId");
            res.remove("hospitalCode");
            res.remove("modifyTime");
            for (Map.Entry<String, Object> entry : res.entrySet()) {
                Object val = entry.getValue();
                if (val == null) {
                    entry.setValue("");
                } else if (!(val instanceof Date)) {
                    entry.setValue(val.toString());
                }
            }
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "查询成功");
            res.put(ResponseMessage.MESSAGE, "查询成功");
            res.put(ResponseMessage.MESSAGE_OUT, "查询成功");
        } else {
            res.put(ResponseMessage.RES_CODE, "-3");
            res.put(ResponseMessage.MESSAGE, "未找到相关记录");
            res.put(ResponseMessage.MESSAGE_IN, "未找到相关记录");
            res.put(ResponseMessage.MESSAGE_OUT, "未找到相关记录");
        }
        return res;
    }

    /**
     * @param channelCode
     * @param hospitalCode
     * @param recordId     挂号ID
     * @return 预约报到交易撤销
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> canceleAppointTransaction(String channelCode, String hospitalCode, String recordId, String patientId) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        String method = "send";
        Map<String, Object> params = new HashMap<>(16);
        params.put("channelCode", channelCode);
        params.put("id", recordId);
        Map<String, Object> recordMap = clinicAppointmentRecordDao.findOne(params);
        if (recordMap != null) {
            recordMap.put("patientId", patientId);
            Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
            Transfer transfer = new CanceleAppointTransactionTransfer(method, client, "TranCancel");
            Map<String, Object> resMap = transfer.transfer(recordMap);
            if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
                params.put("state", "0");
                clinicAppointmentRecordDao.modify(params);
                res.putAll(resMap);
                res.put(ResponseMessage.RES_CODE, "0");
                res.put(ResponseMessage.MESSAGE_IN, "预约报到交易撤销成功");
                res.put(ResponseMessage.MESSAGE, "预约报到交易撤销成功");
                res.put(ResponseMessage.MESSAGE_OUT, "预约报到交易撤销成功");
            } else {
                String executeMessage = (String) resMap.get("message");
                res.put(ResponseMessage.RES_CODE, "0");
                res.put(ResponseMessage.MESSAGE_IN, executeMessage);
                res.put(ResponseMessage.MESSAGE, executeMessage);
                res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
            }
        } else {
            res.put(ResponseMessage.RES_CODE, "-3");
            res.put(ResponseMessage.MESSAGE, "未找到相关记录");
            res.put(ResponseMessage.MESSAGE_IN, "未找到相关记录");
            res.put(ResponseMessage.MESSAGE_OUT, "未找到相关记录");
        }

        return res;
    }

    /**
     * @param channelCode
     * @param hospitalCode
     * @param recordId     挂号ID
     * @param patientId
     * @return 当日挂号交易撤销
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> canceleRegisterTransaction(String channelCode, String hospitalCode, String recordId, String patientId) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        String method = "send";
        Map<String, Object> params = new HashMap<>(16);
        params.put("channelCode", channelCode);
        params.put("hospitalCode", hospitalCode);
        params.put("id", recordId);
        Map<String, Object> recordMap = clinicAppointmentRecordDao.findOne(params);
        if (recordMap != null) {
            recordMap.put("patientId", patientId);
            Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
            Transfer transfer = new CanceleRegisterTransactionTransfer(method, client, "TranCancel");
            Map<String, Object> resMap = transfer.transfer(recordMap);
            if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
                params.put("state", "7");
                clinicAppointmentRecordDao.modify(params);
                res.putAll(resMap);
                res.put(ResponseMessage.RES_CODE, "0");
                res.put(ResponseMessage.MESSAGE_IN, "当日挂号交易撤销成功");
                res.put(ResponseMessage.MESSAGE, "当日挂号交易撤销成功");
                res.put(ResponseMessage.MESSAGE_OUT, "当日挂号交易撤销成功");
            } else {
                String executeMessage = (String) resMap.get("message");
                res.put(ResponseMessage.RES_CODE, "-1");
                res.put(ResponseMessage.MESSAGE_IN, executeMessage);
                res.put(ResponseMessage.MESSAGE, executeMessage);
                res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
            }
        } else {
            res.put(ResponseMessage.RES_CODE, "-3");
            res.put(ResponseMessage.MESSAGE, "未找到相关记录");
            res.put(ResponseMessage.MESSAGE_IN, "未找到相关记录");
            res.put(ResponseMessage.MESSAGE_OUT, "未找到相关记录");
        }

        return res;
    }

    /**
     * 获取诊间挂号列表
     *
     * @param channelCode
     * @param hospitalCode
     * @param startTime
     * @param endTime
     * @param idCard
     * @return
     * @throws Exception
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> loadRegistRecordsForClinicCharge(String channelCode, String hospitalCode, String startTime, String endTime, String idCard, String userName) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        String method = "send";
        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
        Transfer transfer = new LoadRegistRecordsForClinicChargeTransfer(method, client, "GetRegistNew");
        Map<String, Object> params = new HashMap<>(16);
        params.put("startTime", startTime);
        params.put("endTime", endTime);
        params.put("idCard", idCard);
        Map<String, Object> resultMap = transfer.transfer(params);
        if (Dialect.getSuccessfulState().equals(resultMap.get(ResponseMessage.RES_CODE))) {
            List<Map<String, Object>> dateList = (List<Map<String, Object>>) resultMap.get("dateList");
            if (dateList != null && dateList.size() > 0) {
                for (Map<String, Object> dateSubMap : dateList) {
                    List<Map<String, Object>> resList = (List<Map<String, Object>>) dateSubMap.get("resList");
                    for (Map<String, Object> subMap : resList) {
                        Map<String, Object> paramsMap = new HashMap<>(16);
                        paramsMap.put("hisClinicAppointsId", subMap.get("hisClinicAppointsId"));
                        paramsMap.put("appointId", subMap.get("appointId"));
                        paramsMap.put("channelCode", channelCode);
                        paramsMap.put("hospitalCode", hospitalCode);
                        paramsMap.put("rcptNo", subMap.get("rcptNo"));
                        Map<String, Object> daoResMap = clinicAppointmentRecordDao.findOne(paramsMap);
                        String recordId = "";
                        if (daoResMap != null) {
                            recordId = (String) daoResMap.get("id");
                            if (!(subMap.get("state").equals(daoResMap.get("state")))) {
                                paramsMap.put("state", subMap.get("state"));
                                paramsMap.put("clinicFee", subMap.get("clinicFee"));
                                paramsMap.put("totalCost", subMap.get("totalCost"));
                                paramsMap.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
                                paramsMap.put("innerSort", subMap.get("innerSort"));
                                paramsMap.put("queueNum", subMap.get("queueNum"));
                                paramsMap.put("insurVisitId", subMap.get("insurVisitId"));
                                paramsMap.put("insurPay", subMap.get("insurPay"));
                                paramsMap.put("insurAccountPay", subMap.get("accountPay"));
                                paramsMap.put("ownPay", subMap.get("ownPay"));
                                paramsMap.put("rcptNo", subMap.get("rcptNo"));
                                paramsMap.put("visitNo", subMap.get("visitNo"));
                                paramsMap.put("id", daoResMap.get("id"));
                                clinicAppointmentRecordDao.modify(paramsMap);
                            }
                        } else {
                            String id = DataFormatUtils.getTimeStringNoSpace(new Date()) + hospitalCode + channelCode + IdGenerator.getSixRandNum();
                            recordId = id;
                            paramsMap.put("id", id);
                            paramsMap.put("hospitalCode", hospitalCode);
                            paramsMap.put("user", userName);
                            paramsMap.put("personId", idCard);
                            paramsMap.put("idCard", idCard);
                            paramsMap.put("name", subMap.get("name"));
                            paramsMap.put("phone", subMap.get("phone"));
                            paramsMap.put("clinicLabel", subMap.get("clinicLabel"));
                            paramsMap.put("patientType", subMap.get("patientType"));
                            paramsMap.put("appointDate", subMap.get("appointDate"));
                            paramsMap.put("transactNo", subMap.get("transactNo"));
                            paramsMap.put("ampm", subMap.get("ampm"));
                            paramsMap.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
                            paramsMap.put("deptCode", subMap.get("deptCode"));
                            paramsMap.put("doctorTitleCode", subMap.get("doctorTitleCode"));
                            paramsMap.put("innerSort", subMap.get("innerSort"));
                            paramsMap.put("queueNum", subMap.get("queueNum"));
                            paramsMap.put("state", subMap.get("state"));
                            paramsMap.put("appointmentType", "1");
                            paramsMap.put("clinicFee", subMap.get("clinicFee"));
                            paramsMap.put("deptAddress", subMap.get("deptAddress"));
                            paramsMap.put("totalCost", subMap.get("totalCost"));
                            paramsMap.put("insurVisitId", subMap.get("insurVisitId"));
                            paramsMap.put("insurPay", subMap.get("insurPay"));
                            paramsMap.put("insurAccountPay", subMap.get("accountPay"));
                            paramsMap.put("ownPay", subMap.get("ownPay"));
                            paramsMap.put("rcptNo", subMap.get("rcptNo"));
                            paramsMap.put("visitNo", subMap.get("visitNo"));
                            paramsMap.put("cardId", subMap.get("cardId"));
                            clinicAppointmentRecordDao.add(paramsMap);
                        }
                        subMap.put("recordId", recordId);
                        subMap.remove("hisClinicAppointsId");
                        subMap.remove("appointId");
                        subMap.remove("rcptNo");
//                        subMap.remove("name");
                        subMap.remove("patientType");
                        subMap.remove("appointDate");
                        subMap.remove("ampm");
                        subMap.remove("doctorTitleCode");
                        subMap.remove("innerSort");
                        subMap.remove("queueNum");
                        subMap.remove("state");
                        subMap.remove("clinicFee");
                        subMap.remove("deptAddress");
                        subMap.remove("totalCost");
                        subMap.remove("insurVisitId");
                        subMap.remove("insurPay");
                        subMap.remove("insurAccountPay");
                        subMap.remove("ownPay");
                        subMap.remove("cardId");
                    }
                }
            }
            res.put("dateList", resultMap.get("dateList"));
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "查询挂号列表成功");
            res.put(ResponseMessage.MESSAGE, "查询挂号列表成功");
            res.put(ResponseMessage.MESSAGE_OUT, "查询挂号列表成功");
        } else {
            String executeMessage = (String) resultMap.get("message");
            res.put(ResponseMessage.RES_CODE, "-26");
            res.put(ResponseMessage.MESSAGE_IN, executeMessage);
            res.put(ResponseMessage.MESSAGE, executeMessage);
            res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
        }

        return res;
    }


    @Override
    public Map<String, Object> loadExamList(String startDate, String endDate, String cardNo) throws Exception {
        Map<String, Object> res = new HashMap<>();
        String method = "send";
        Map<String, Object> params = new HashMap<>();
        params.put("startDate", startDate);
        params.put("endDate", endDate);
//        params.put("cardNo", cardNo);
        params.put("patientId", cardNo);
//        params.put("idCard",cardNo);
//        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
//        Transfer transfer = new QueryPatientInfoTransfer(method, client,"GetPatient");
//        Map<String, Object> dataMap = transfer.transfer(params);
//        if (Dialect.getSuccessfulState().equals(dataMap.get(ResponseMessage.RES_CODE))) {
//            params.put("patientId",dataMap.get("patientId"));
//        }
        String str = HttpClientSupport.doPost("http://localhost:8099/report/report/searchExamMasterList/", JSON.toJSONString(params), "UTF-8");
        JSONArray resJson = JSON.parseArray(str);
        List<Map<String, Object>> dataList = new ArrayList<>();
        if (resJson.size() > 0) {
            for (int i = 0; i < resJson.size(); i++) {
                Map<String, Object> paramsMap = new HashMap<>();
                JSONObject jsondata = resJson.getJSONObject(i);
                paramsMap.put("deptName", jsondata.getString("reqDept"));//申请科室
                paramsMap.put("description", jsondata.getString("description"));//报告描述
                paramsMap.put("diagnosis", jsondata.getString("clinDiag"));//报告诊断
                paramsMap.put("docName", jsondata.getString("reqPhysician"));//申请医生
                paramsMap.put("regTime", jsondata.getString("reqDateTime"));//登记时间
                paramsMap.put("part", jsondata.getString("examSubClass"));//部位
                paramsMap.put("repTime", jsondata.getString("reportDateTime"));//报告时间
                paramsMap.put("repId", jsondata.getString("examNo"));//检查项目编码
                paramsMap.put("repName", jsondata.getString("examItem"));//检查项目
                paramsMap.put("suggest", jsondata.getString("impression"));//报告建议impression
                dataList.add(paramsMap);
            }
            res.put("dataList", dataList);
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "查询数据成功");
            res.put(ResponseMessage.MESSAGE, "查询数据成功");
            res.put(ResponseMessage.MESSAGE_OUT, "查询数据成功");
        } else {
            res.put(ResponseMessage.RES_CODE, "-24");
            res.put(ResponseMessage.MESSAGE_IN, "查无数据");
            res.put(ResponseMessage.MESSAGE, "查无数据");
            res.put(ResponseMessage.MESSAGE_OUT, "查无数据");
        }
//        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
//        Transfer transfer = new LoadExamListTransfer(method, client,"GetExam");
//        Map<String, Object> dataMap = transfer.transfer(params);
//        List<Map<String, Object>> dataList = new ArrayList<>();
//        if (Dialect.getSuccessfulState().equals(dataMap.get(ResponseMessage.RES_CODE))) {
//            List<Map<String, Object>> list = (List<Map<String, Object>>) dataMap.get("list");
//            if (list != null && list.size() > 0) {
//                for (Map<String, Object> dateSubMap : list) {
//                    Map<String, Object> paramsMap = new HashMap<>(16);
//                    {
//                        paramsMap.put("deptCode", dateSubMap.get("deptCode"));
//                        paramsMap.put("description", dateSubMap.get("description"));
//                        paramsMap.put("diagnosis", dateSubMap.get("diagnosis"));
//                        paramsMap.put("docName", dateSubMap.get("docName"));
//                        paramsMap.put("regTime", dateSubMap.get("regTime"));
//                        paramsMap.put("part", dateSubMap.get("part"));
//                        paramsMap.put("repTime", dateSubMap.get("repTime"));
//                        paramsMap.put("repId", dateSubMap.get("repId"));
//                        paramsMap.put("repName", dateSubMap.get("repName"));
//                        paramsMap.put("suggest", dateSubMap.get("suggest"));
//                        dataList.add(paramsMap);
//                    }
//                }
//            }
//            res.put("dataList", dataList);
//            res.put(ResponseMessage.RES_CODE, "0");
//            res.put(ResponseMessage.MESSAGE_IN, "查询数据成功");
//            res.put(ResponseMessage.MESSAGE, "查询数据成功");
//            res.put(ResponseMessage.MESSAGE_OUT, "查询数据成功");
//        } else {
//            String executeMessage = (String) dataMap.get("message");
//            res.put(ResponseMessage.RES_CODE, "-24");
//            res.put(ResponseMessage.MESSAGE_IN, executeMessage);
//            res.put(ResponseMessage.MESSAGE, executeMessage);
//            res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
//        }
        return res;
    }
//
//    @Override
//    public Map<String, Object> loadExamList(String startDate, String endDate, String cardNo) throws Exception {
//        Map<String, Object> res = new HashMap<>(16);
//        String method = "send";
//        Map<String, Object> params = new HashMap<>(16);
//        params.put("startDate", startDate);
//        params.put("endDate", endDate);
//        params.put("cardNo", cardNo);
//        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
//        Transfer transfer = new LoadExamListTransfer(method, client,"GetExam");
//        Map<String, Object> dataMap = transfer.transfer(params);
//        List<Map<String, Object>> dataList = new ArrayList<>();
//        if (Dialect.getSuccessfulState().equals(dataMap.get(ResponseMessage.RES_CODE))) {
//            List<Map<String, Object>> list = (List<Map<String, Object>>) dataMap.get("list");
//            if (list != null && list.size() > 0) {
//                for (Map<String, Object> dateSubMap : list) {
//                    Map<String, Object> paramsMap = new HashMap<>(16);
//                    {
//                        paramsMap.put("deptCode", dateSubMap.get("deptCode"));
//                        paramsMap.put("description", dateSubMap.get("description"));
//                        paramsMap.put("diagnosis", dateSubMap.get("diagnosis"));
//                        paramsMap.put("docName", dateSubMap.get("docName"));
//                        paramsMap.put("regTime", dateSubMap.get("regTime"));
//                        paramsMap.put("part", dateSubMap.get("part"));
//                        paramsMap.put("repTime", dateSubMap.get("repTime"));
//                        paramsMap.put("repId", dateSubMap.get("repId"));
//                        paramsMap.put("repName", dateSubMap.get("repName"));
//                        paramsMap.put("suggest", dateSubMap.get("suggest"));
//                        dataList.add(paramsMap);
//                    }
//                }
//            }
//            res.put("dataList", dataList);
//            res.put(ResponseMessage.RES_CODE, "0");
//            res.put(ResponseMessage.MESSAGE_IN, "查询数据成功");
//            res.put(ResponseMessage.MESSAGE, "查询数据成功");
//            res.put(ResponseMessage.MESSAGE_OUT, "查询数据成功");
//        } else {
//            String executeMessage = (String) dataMap.get("message");
//            res.put(ResponseMessage.RES_CODE, "-24");
//            res.put(ResponseMessage.MESSAGE_IN, executeMessage);
//            res.put(ResponseMessage.MESSAGE, executeMessage);
//            res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
//        }
//        return res;
//    }

    @Override
    public Map<String, Object> loadExamDetails(String repId, String cardNo) throws Exception {
        Map<String, Object> res = new HashMap<>();
        String method = "send";
        Map<String, Object> params = new HashMap<>();
        params.put("patientId", cardNo);
        params.put("examNo", repId);
        params.put("idCard", cardNo);
//        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
//        Transfer transfer = new QueryPatientInfoTransfer(method, client,"GetPatient");
//        Map<String, Object> dataMap = transfer.transfer(params);
//        if (Dialect.getSuccessfulState().equals(dataMap.get(ResponseMessage.RES_CODE))) {
//            params.put("patientId",dataMap.get("patientId"));
//        }
        String str = HttpClientSupport.doPost("http://localhost:8099/report/report/searchExamResultList/", JSON.toJSONString(params), "UTF-8");
        JSONArray resJson = JSON.parseArray(str);
        List<Map<String, Object>> dataList = new ArrayList<>();
        if (resJson.size() > 0) {
            for (int i = 0; i < resJson.size(); i++) {
                Map<String, Object> paramsMap = new HashMap<>();
                JSONObject jsondata = resJson.getJSONObject(i);

                paramsMap.put("deptName", jsondata.getString("reqDept"));//申请科室
                paramsMap.put("description", jsondata.getString("description"));//报告描述
                paramsMap.put("diagnosis", jsondata.getString("clinDiag"));//报告诊断
                paramsMap.put("docName", jsondata.getString("reqPhysician"));//申请医生
                paramsMap.put("regTime", jsondata.getString("reqDateTime"));//登记时间
                paramsMap.put("part", jsondata.getString("examSubClass"));//部位
                paramsMap.put("repTime", jsondata.getString("reportDateTime"));//报告时间
                paramsMap.put("repId", jsondata.getString("examNo"));//检查项目编码
                paramsMap.put("repName", jsondata.getString("examItem"));//检查项目
                paramsMap.put("suggest", jsondata.getString("impression"));//报告建议impression
                dataList.add(paramsMap);
            }
            res.put("dataList", dataList);
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "查询数据成功");
            res.put(ResponseMessage.MESSAGE, "查询数据成功");
            res.put(ResponseMessage.MESSAGE_OUT, "查询数据成功");
        } else {
            res.put(ResponseMessage.RES_CODE, "-24");
            res.put(ResponseMessage.MESSAGE_IN, "查无数据");
            res.put(ResponseMessage.MESSAGE, "查无数据");
            res.put(ResponseMessage.MESSAGE_OUT, "查无数据");
        }
        //        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
//        Transfer transfer = new LoadExamDetailsTransfer(method, client,"GetExam");
//        Map<String, Object> dataMap = transfer.transfer(params);
//        List<Map<String, Object>> dataList = new ArrayList<>();
//        if (Dialect.getSuccessfulState().equals(dataMap.get(ResponseMessage.RES_CODE))) {
//            List<Map<String, Object>> list = (List<Map<String, Object>>) dataMap.get("list");
//            if (list != null && list.size() > 0) {
//                for (Map<String, Object> dateSubMap : list) {
//                    Map<String, Object> paramsMap = new HashMap<>(16);
//                    {
//                        paramsMap.put("deptCode", dateSubMap.get("deptCode"));
//                        paramsMap.put("description", dateSubMap.get("description"));
//                        paramsMap.put("diagnosis", dateSubMap.get("diagnosis"));
//                        paramsMap.put("docName", dateSubMap.get("docName"));
//                        paramsMap.put("regTime", dateSubMap.get("regTime"));
//                        paramsMap.put("part", dateSubMap.get("part"));
//                        paramsMap.put("repTime", dateSubMap.get("repTime"));
//                        paramsMap.put("repId", dateSubMap.get("repId"));
//                        paramsMap.put("repName", dateSubMap.get("repName"));
//                        paramsMap.put("suggest", dateSubMap.get("suggest"));
//                        dataList.add(paramsMap);
//                    }
//                }
//            }
//            res.put("dataList", dataList);
//            res.put(ResponseMessage.RES_CODE, "0");
//            res.put(ResponseMessage.MESSAGE_IN, "查询数据成功");
//            res.put(ResponseMessage.MESSAGE, "查询数据成功");
//            res.put(ResponseMessage.MESSAGE_OUT, "查询数据成功");
//        } else {
//            String executeMessage = (String) dataMap.get("message");
//            res.put(ResponseMessage.RES_CODE, "-24");
//            res.put(ResponseMessage.MESSAGE_IN, executeMessage);
//            res.put(ResponseMessage.MESSAGE, executeMessage);
//            res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
//        }
        return res;
    }
//
//    @Override
//    public Map<String, Object> loadExamDetails(String repId, String cardNo) throws Exception {
//        Map<String, Object> res = new HashMap<>(16);
//        String method = "send";
//        Map<String, Object> params = new HashMap<>(16);
//        params.put("cardNo", cardNo);
//        params.put("repId", repId);
//        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
//        Transfer transfer = new LoadExamDetailsTransfer(method, client,"GetExam");
//        Map<String, Object> dataMap = transfer.transfer(params);
//        List<Map<String, Object>> dataList = new ArrayList<>();
//        if (Dialect.getSuccessfulState().equals(dataMap.get(ResponseMessage.RES_CODE))) {
//            List<Map<String, Object>> list = (List<Map<String, Object>>) dataMap.get("list");
//            if (list != null && list.size() > 0) {
//                for (Map<String, Object> dateSubMap : list) {
//                    Map<String, Object> paramsMap = new HashMap<>(16);
//                    {
//                        paramsMap.put("deptCode", dateSubMap.get("deptCode"));
//                        paramsMap.put("description", dateSubMap.get("description"));
//                        paramsMap.put("diagnosis", dateSubMap.get("diagnosis"));
//                        paramsMap.put("docName", dateSubMap.get("docName"));
//                        paramsMap.put("regTime", dateSubMap.get("regTime"));
//                        paramsMap.put("part", dateSubMap.get("part"));
//                        paramsMap.put("repTime", dateSubMap.get("repTime"));
//                        paramsMap.put("repId", dateSubMap.get("repId"));
//                        paramsMap.put("repName", dateSubMap.get("repName"));
//                        paramsMap.put("suggest", dateSubMap.get("suggest"));
//                        dataList.add(paramsMap);
//                    }
//                }
//            }
//            res.put("dataList", dataList);
//            res.put(ResponseMessage.RES_CODE, "0");
//            res.put(ResponseMessage.MESSAGE_IN, "查询数据成功");
//            res.put(ResponseMessage.MESSAGE, "查询数据成功");
//            res.put(ResponseMessage.MESSAGE_OUT, "查询数据成功");
//        } else {
//            String executeMessage = (String) dataMap.get("message");
//            res.put(ResponseMessage.RES_CODE, "-24");
//            res.put(ResponseMessage.MESSAGE_IN, executeMessage);
//            res.put(ResponseMessage.MESSAGE, executeMessage);
//            res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
//        }
//        return res;
//    }

    @Override
    public Map<String, Object> loadLabMasterList(String startDate, String endDate, String cardNo) throws Exception {
        Map<String, Object> res = new HashMap<>();
        String method = "send";
        Map<String, Object> params = new HashMap<>();
        params.put("startDate", startDate);
        params.put("endDate", endDate);
//        params.put("cardNo", cardNo);
        params.put("patientId", cardNo);
//        params.put("idCard",cardNo);
//        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
//        Transfer transfer = new QueryPatientInfoTransfer(method, client,"GetPatient");
//        Map<String, Object> dataMap = transfer.transfer(params);
//        if (Dialect.getSuccessfulState().equals(dataMap.get(ResponseMessage.RES_CODE))) {
//            params.put("patientId",dataMap.get("patientId"));
//        }
        String str = HttpClientSupport.doPost("http://localhost:8099/report/report/searchLabMasterList/", JSON.toJSONString(params), "UTF-8");
        JSONArray resJson = JSON.parseArray(str);
        if (resJson.size() > 0) {
            List<Map<String, Object>> dataList = new ArrayList<>();
            for (int i = 0; i < resJson.size(); i++) {
                JSONObject jsondata = resJson.getJSONObject(i);
                Map<String, Object> paramsMap = new HashMap<>();
                paramsMap.put("repId", jsondata.getString("testNo"));
                paramsMap.put("repTime", jsondata.getString("resultsRptDateTime"));
                paramsMap.put("deptName", jsondata.getString("orderingDept"));
                paramsMap.put("docName", jsondata.getString("orderingProvider"));
                paramsMap.put("itemNo", jsondata.getString("itemNo"));
                paramsMap.put("repName", jsondata.getString("itemName"));
                paramsMap.put("specimen", jsondata.getString("specimen"));
                paramsMap.put("regTime", jsondata.getString("requestedDateTime"));
                dataList.add(paramsMap);
            }
            res.put("dataList", dataList);
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "查询数据成功");
            res.put(ResponseMessage.MESSAGE, "查询数据成功");
            res.put(ResponseMessage.MESSAGE_OUT, "查询数据成功");
        } else {
            res.put(ResponseMessage.RES_CODE, "-24");
            res.put(ResponseMessage.MESSAGE_IN, "查无数据");
            res.put(ResponseMessage.MESSAGE, "查无数据");
            res.put(ResponseMessage.MESSAGE_OUT, "查无数据");
        }

//        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
//        Transfer transfer = new LoadLabMasterListTransfer(method, client,"GetLabMaster");
//        Map<String, Object> dataMap = transfer.transfer(params);
//        List<Map<String, Object>> dataList = new ArrayList<>();
//        if (Dialect.getSuccessfulState().equals(dataMap.get(ResponseMessage.RES_CODE))) {
//            List<Map<String, Object>> list = (List<Map<String, Object>>) dataMap.get("list");
//            if (list != null && list.size() > 0) {
//                for (Map<String, Object> dateSubMap : list) {
//                    Map<String, Object> paramsMap = new HashMap<>(16);
//                    {
//                        paramsMap.put("repId", dateSubMap.get("repId"));
//                        paramsMap.put("repTime", dateSubMap.get("repTime"));
//                        paramsMap.put("deptName", dateSubMap.get("deptName"));
//                        paramsMap.put("docName", dateSubMap.get("docName"));
//                        paramsMap.put("itemNo", dateSubMap.get("itemNo"));
//                        paramsMap.put("repName", dateSubMap.get("repName"));
//                        paramsMap.put("specimen", dateSubMap.get("specimen"));
//                        paramsMap.put("regTime", dateSubMap.get("regTime"));
//                        dataList.add(paramsMap);
//                    }
//                }
//            }
//            res.put("dataList", dataList);
//            res.put(ResponseMessage.RES_CODE, "0");
//            res.put(ResponseMessage.MESSAGE_IN, "查询数据成功");
//            res.put(ResponseMessage.MESSAGE, "查询数据成功");
//            res.put(ResponseMessage.MESSAGE_OUT, "查询数据成功");
//        } else {
//            String executeMessage = (String) dataMap.get("message");
//            res.put(ResponseMessage.RES_CODE, "-24");
//            res.put(ResponseMessage.MESSAGE_IN, executeMessage);
//            res.put(ResponseMessage.MESSAGE, executeMessage);
//            res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
//        }
        return res;
    }
//    @Override
//    public Map<String, Object> loadLabMasterList(String startDate, String endDate, String cardNo) throws Exception {
//        Map<String, Object> res = new HashMap<>(16);
//        String method = "send";
//        Map<String, Object> params = new HashMap<>(16);
//        params.put("startDate", startDate);
//        params.put("endDate", endDate);
//        params.put("cardNo", cardNo);
//        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
//        Transfer transfer = new LoadLabMasterListTransfer(method, client,"GetLabMaster");
//        Map<String, Object> dataMap = transfer.transfer(params);
//        List<Map<String, Object>> dataList = new ArrayList<>();
//        if (Dialect.getSuccessfulState().equals(dataMap.get(ResponseMessage.RES_CODE))) {
//            List<Map<String, Object>> list = (List<Map<String, Object>>) dataMap.get("list");
//            if (list != null && list.size() > 0) {
//                for (Map<String, Object> dateSubMap : list) {
//                    Map<String, Object> paramsMap = new HashMap<>(16);
//                    {
//                        paramsMap.put("repId", dateSubMap.get("repId"));
//                        paramsMap.put("repTime", dateSubMap.get("repTime"));
//                        paramsMap.put("deptName", dateSubMap.get("deptName"));
//                        paramsMap.put("docName", dateSubMap.get("docName"));
//                        paramsMap.put("itemNo", dateSubMap.get("itemNo"));
//                        paramsMap.put("repName", dateSubMap.get("repName"));
//                        paramsMap.put("specimen", dateSubMap.get("specimen"));
//                        paramsMap.put("regTime", dateSubMap.get("regTime"));
//                        dataList.add(paramsMap);
//                    }
//                }
//            }
//            res.put("dataList", dataList);
//            res.put(ResponseMessage.RES_CODE, "0");
//            res.put(ResponseMessage.MESSAGE_IN, "查询数据成功");
//            res.put(ResponseMessage.MESSAGE, "查询数据成功");
//            res.put(ResponseMessage.MESSAGE_OUT, "查询数据成功");
//        } else {
//            String executeMessage = (String) dataMap.get("message");
//            res.put(ResponseMessage.RES_CODE, "-24");
//            res.put(ResponseMessage.MESSAGE_IN, executeMessage);
//            res.put(ResponseMessage.MESSAGE, executeMessage);
//            res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
//        }
//        return res;
//    }

    @Override
    public Map<String, Object> loadLabMasterDetails(String repId, String cardNo) throws Exception {
        Map<String, Object> res = new HashMap<>();
        String method = "send";
        Map<String, Object> params = new HashMap<>();
        params.put("repId", repId);
        params.put("patientId", cardNo);
//        params.put("idCard",cardNo);
//        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
//        Transfer transfer = new QueryPatientInfoTransfer(method, client,"GetPatient");
//        Map<String, Object> dataMap = transfer.transfer(params);
//        if (Dialect.getSuccessfulState().equals(dataMap.get(ResponseMessage.RES_CODE))) {
//            params.put("patientId",dataMap.get("patientId"));
//        }
        String str = HttpClientSupport.doPost("http://localhost:8099/report/report/searchLabResultList/", JSON.toJSONString(params), "UTF-8");
        JSONArray resJson = JSON.parseArray(str);
        if (resJson.size() > 0) {
            List<Map<String, Object>> dataList = new ArrayList<>();
            for (int i = 0; i < resJson.size(); i++) {
                JSONObject jsondata = resJson.getJSONObject(i);
                Map<String, Object> paramsMap = new HashMap<>();

                paramsMap.put("itemCode", jsondata.getString("reportItemCode"));
                paramsMap.put("repName", jsondata.getString("reportItemName"));
                paramsMap.put("itemName", jsondata.getString("itemName"));
                paramsMap.put("itemVal", jsondata.getString("result"));
                paramsMap.put("itemUnits", jsondata.getString("units"));
                paramsMap.put("normalVal", jsondata.getString("refRange"));
                paramsMap.put("flag", jsondata.getString("abnormalIndicator"));
                if ((jsondata.getString("abnormalIndicator")).equals("H")) {
                    String flagName = "↑";
                    paramsMap.put("flagName", flagName);
                }
                if ((jsondata.getString("abnormalIndicator")).equals("L")) {
                    String flagName = "↓";
                    paramsMap.put("flagName", flagName);
                }
                if ((jsondata.getString("abnormalIndicator")).equals("N")) {
                    String flagName = "";
                    paramsMap.put("flagName", flagName);
                }
                if ((jsondata.getString("abnormalIndicator")).equals("")) {
                    String flagName = "";
                    paramsMap.put("flagName", flagName);
                }
                if ((jsondata.getString("abnormalIndicator")).equals("HH")) {
                    String flagName = "↑↑";
                    paramsMap.put("flagName", flagName);
                }
                if ((jsondata.getString("abnormalIndicator")).equals("LL")) {
                    String flagName = "↓↓";
                    paramsMap.put("flagName", flagName);
                }
                if ((jsondata.getString("abnormalIndicator")).equals("阴性")) {
                    String flagName = "阴性";
                    paramsMap.put("flagName", flagName);
                }
                if ((jsondata.getString("abnormalIndicator")).equals("阳性")) {
                    String flagName = "阳性";
                    paramsMap.put("flagName", flagName);
                }
                if ((jsondata.getString("abnormalIndicator")).equals("敏感")) {
                    String flagName = "敏感";
                    paramsMap.put("flagName", flagName);
                }
                if ((jsondata.getString("abnormalIndicator")).equals("未知")) {
                    String flagName = "未知";
                    paramsMap.put("flagName", flagName);
                }
                if ((jsondata.getString("abnormalIndicator")).equals("耐药")) {
                    String flagName = "耐药";
                    paramsMap.put("flagName", flagName);
                }
                if ((jsondata.getString("abnormalIndicator")).equals("中介")) {
                    String flagName = "中介";
                    paramsMap.put("flagName", flagName);
                }
                dataList.add(paramsMap);
            }
            res.put("dataList", dataList);
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "查询数据成功");
            res.put(ResponseMessage.MESSAGE, "查询数据成功");
            res.put(ResponseMessage.MESSAGE_OUT, "查询数据成功");
        } else {
            res.put(ResponseMessage.RES_CODE, "-24");
            res.put(ResponseMessage.MESSAGE_IN, "查无数据");
            res.put(ResponseMessage.MESSAGE, "查无数据");
            res.put(ResponseMessage.MESSAGE_OUT, "查无数据");
        }

//        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
//        Transfer transfer = new LoadLabMasterDetailsTransfer(method, client,"GetLabItemResult");
//        Map<String, Object> dataMap = transfer.transfer(params);
//        List<Map<String, Object>> dataList = new ArrayList<>();
//        if (Dialect.getSuccessfulState().equals(dataMap.get(ResponseMessage.RES_CODE))) {
//            List<Map<String, Object>> list = (List<Map<String, Object>>) dataMap.get("list");
//            if (list != null && list.size() > 0) {
//                for (Map<String, Object> dateSubMap : list) {
//                    Map<String, Object> paramsMap = new HashMap<>(16);
//                    {
//                        paramsMap.put("itemCode", dateSubMap.get("itemCode"));
//                        paramsMap.put("repName", dateSubMap.get("repName"));
//                        paramsMap.put("itemName", dateSubMap.get("itemName"));
//                        paramsMap.put("itemVal", dateSubMap.get("itemVal"));
//                        paramsMap.put("itemUnits", dateSubMap.get("itemUnits"));
//                        paramsMap.put("normalVal", dateSubMap.get("normalVal"));
//                        paramsMap.put("flag", dateSubMap.get("flag"));
//                       if((dateSubMap.get("flag")).equals("H")){
//                           String flagName = "↑";
//                           paramsMap.put("flagName", flagName);
//                       }
//                        if((dateSubMap.get("flag")).equals("L")){
//                            String flagName = "↓";
//                            paramsMap.put("flagName", flagName);
//                        }
//                        if((dateSubMap.get("flag")).equals("N")){
//                            String flagName = "";
//                            paramsMap.put("flagName", flagName);
//                        }
//                        if((dateSubMap.get("flag")).equals("")){
//                            String flagName = "";
//                            paramsMap.put("flagName", flagName);
//                        }
//                        if((dateSubMap.get("flag")).equals("HH")){
//                            String flagName = "↑↑";
//                            paramsMap.put("flagName", flagName);
//                        }
//                        if((dateSubMap.get("flag")).equals("LL")){
//                            String flagName = "↓↓";
//                            paramsMap.put("flagName", flagName);
//                        }
//                        if((dateSubMap.get("flag")).equals("阴性")){
//                            String flagName = "阴性";
//                            paramsMap.put("flagName", flagName);
//                        }
//                        if((dateSubMap.get("flag")).equals("阳性")){
//                            String flagName = "阳性";
//                            paramsMap.put("flagName", flagName);
//                        }
//                        if((dateSubMap.get("flag")).equals("敏感")){
//                            String flagName = "敏感";
//                            paramsMap.put("flagName", flagName);
//                        }
//                        if((dateSubMap.get("flag")).equals("未知")){
//                            String flagName = "未知";
//                            paramsMap.put("flagName", flagName);
//                        }
//                        if((dateSubMap.get("flag")).equals("耐药")){
//                            String flagName = "耐药";
//                            paramsMap.put("flagName", flagName);
//                        }
//                        if((dateSubMap.get("flag")).equals("中介")){
//                            String flagName = "中介";
//                            paramsMap.put("flagName", flagName);
//                        }
//                        dataList.add(paramsMap);
//                    }
//                }
//            }
//            res.put("dataList", dataList);
//            res.put(ResponseMessage.RES_CODE, "0");
//            res.put(ResponseMessage.MESSAGE_IN, "查询数据成功");
//            res.put(ResponseMessage.MESSAGE, "查询数据成功");
//            res.put(ResponseMessage.MESSAGE_OUT, "查询数据成功");
//        } else {
//            String executeMessage = (String) dataMap.get("message");
//            res.put(ResponseMessage.RES_CODE, "-24");
//            res.put(ResponseMessage.MESSAGE_IN, executeMessage);
//            res.put(ResponseMessage.MESSAGE, executeMessage);
//            res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
//        }
        return res;
    }


//    @Override
//    public Map<String, Object> loadLabMasterDetails(String repId, String cardNo) throws Exception {
//        Map<String, Object> res = new HashMap<>(16);
//        String method = "send";
//        Map<String, Object> params = new HashMap<>(16);
//        params.put("repId", repId);
//        params.put("cardNo", cardNo);
//        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
//        Transfer transfer = new LoadLabMasterDetailsTransfer(method, client,"GetLabItemResult");
//        Map<String, Object> dataMap = transfer.transfer(params);
//        List<Map<String, Object>> dataList = new ArrayList<>();
//        if (Dialect.getSuccessfulState().equals(dataMap.get(ResponseMessage.RES_CODE))) {
//            List<Map<String, Object>> list = (List<Map<String, Object>>) dataMap.get("list");
//            if (list != null && list.size() > 0) {
//                for (Map<String, Object> dateSubMap : list) {
//                    Map<String, Object> paramsMap = new HashMap<>(16);
//                    {
//                        paramsMap.put("itemCode", dateSubMap.get("itemCode"));
//                        paramsMap.put("repName", dateSubMap.get("repName"));
//                        paramsMap.put("itemName", dateSubMap.get("itemName"));
//                        paramsMap.put("itemVal", dateSubMap.get("itemVal"));
//                        paramsMap.put("itemUnits", dateSubMap.get("itemUnits"));
//                        paramsMap.put("normalVal", dateSubMap.get("normalVal"));
//                        paramsMap.put("flag", dateSubMap.get("flag"));
//                       if((dateSubMap.get("flag")).equals("H")){
//                           String flagName = "↑";
//                           paramsMap.put("flagName", flagName);
//                       }
//                        if((dateSubMap.get("flag")).equals("L")){
//                            String flagName = "↓";
//                            paramsMap.put("flagName", flagName);
//                        }
//                        if((dateSubMap.get("flag")).equals("N")){
//                            String flagName = "";
//                            paramsMap.put("flagName", flagName);
//                        }
//                        if((dateSubMap.get("flag")).equals("")){
//                            String flagName = "";
//                            paramsMap.put("flagName", flagName);
//                        }
//                        if((dateSubMap.get("flag")).equals("HH")){
//                            String flagName = "↑↑";
//                            paramsMap.put("flagName", flagName);
//                        }
//                        if((dateSubMap.get("flag")).equals("LL")){
//                            String flagName = "↓↓";
//                            paramsMap.put("flagName", flagName);
//                        }
//                        if((dateSubMap.get("flag")).equals("阴性")){
//                            String flagName = "阴性";
//                            paramsMap.put("flagName", flagName);
//                        }
//                        if((dateSubMap.get("flag")).equals("阳性")){
//                            String flagName = "阳性";
//                            paramsMap.put("flagName", flagName);
//                        }
//                        if((dateSubMap.get("flag")).equals("敏感")){
//                            String flagName = "敏感";
//                            paramsMap.put("flagName", flagName);
//                        }
//                        if((dateSubMap.get("flag")).equals("未知")){
//                            String flagName = "未知";
//                            paramsMap.put("flagName", flagName);
//                        }
//                        if((dateSubMap.get("flag")).equals("耐药")){
//                            String flagName = "耐药";
//                            paramsMap.put("flagName", flagName);
//                        }
//                        if((dateSubMap.get("flag")).equals("中介")){
//                            String flagName = "中介";
//                            paramsMap.put("flagName", flagName);
//                        }
//                        dataList.add(paramsMap);
//                    }
//                }
//            }
//            res.put("dataList", dataList);
//            res.put(ResponseMessage.RES_CODE, "0");
//            res.put(ResponseMessage.MESSAGE_IN, "查询数据成功");
//            res.put(ResponseMessage.MESSAGE, "查询数据成功");
//            res.put(ResponseMessage.MESSAGE_OUT, "查询数据成功");
//        } else {
//            String executeMessage = (String) dataMap.get("message");
//            res.put(ResponseMessage.RES_CODE, "-24");
//            res.put(ResponseMessage.MESSAGE_IN, executeMessage);
//            res.put(ResponseMessage.MESSAGE, executeMessage);
//            res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
//        }
//        return res;
//    }


    @Override
    public Map<String, Object> loadCallNo(String cardNo, String hospitalCode) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        String method = "send";
        Map<String, Object> params = new HashMap<>(16);
        params.put("cardNo", cardNo);
        params.put("hospitalCode", "0001");
        params.put("personId", cardNo);
        Map<String, Object> respersonDao = personDao.findOne(params);
        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
        Transfer transfer = new LoadCallNoTransfer(method, client, "GetCallNoForXK");
        Map<String, Object> dataMap = transfer.transfer(params);
        List<Map<String, Object>> dataList = new ArrayList<>();
        if (Dialect.getSuccessfulState().equals(dataMap.get(ResponseMessage.RES_CODE))) {
            List<Map<String, Object>> list = (List<Map<String, Object>>) dataMap.get("list");
            if (list != null && list.size() > 0) {
                for (Map<String, Object> dateSubMap : list) {
                    if ((dateSubMap.get("state")).equals("0") || (dateSubMap.get("state")).equals("1")) {
                        Map<String, Object> paramsMap = new HashMap<>(16);
                        params.put("deptCode", dateSubMap.get("deptCode"));
                        Map<String, Object> reshospitalDeptDao = deptDao.findOne(params);
                        {
                            String state = "无";
                            state = (String) dateSubMap.get("state");

                            if (reshospitalDeptDao != null) {
//                            paramsMap.put("deptCode", dateSubMap.get("deptCode"));
                                paramsMap.put("deptName", reshospitalDeptDao.get("deptName"));
                                paramsMap.put("docName", dateSubMap.get("docName"));
                                paramsMap.put("ampm", dateSubMap.get("ampm"));
                                paramsMap.put("no", dateSubMap.get("no"));
                                paramsMap.put("curNo", dateSubMap.get("curNo"));
                                paramsMap.put("beforeNum", dateSubMap.get("beforeNum"));
                                paramsMap.put("visitDate", dateSubMap.get("visitDate"));
                                paramsMap.put("state", dateSubMap.get("state"));
                                paramsMap.put("stateName", Dialect.getCallNoState(state));
                                paramsMap.put("date", DataFormatUtils.parserDayTemp((String) dateSubMap.get("visitDate")));
                                dataList.add(paramsMap);
                                if (dataList.get(0).get("date") != null) {
                                    res.put("date", DataFormatUtils.getSimpleTimeString((Date) dataList.get(0).get("date")));
                                }
                            }
                        }
                    }

//            }
//                    if(dataList.get(0).get("date")!=null) {
//                        res.put("date", DataFormatUtils.getSimpleTimeString((Date) dataList.get(0).get("date")));
//                    }
                }
                String name = (String) respersonDao.get("name");
                res.put("name", name);
                res.put("dataList", dataList);
                res.put(ResponseMessage.RES_CODE, "0");
                res.put(ResponseMessage.MESSAGE_IN, "查询数据成功");
                res.put(ResponseMessage.MESSAGE, "查询数据成功");
                res.put(ResponseMessage.MESSAGE_OUT, "查询数据成功");
            } else {
                res.put(ResponseMessage.RES_CODE, "0");
                res.put(ResponseMessage.MESSAGE_IN, "查询数据成功");
                res.put(ResponseMessage.MESSAGE, "查询数据成功");
                res.put(ResponseMessage.MESSAGE_OUT, "查询数据成功");
            }
        } else {
            String executeMessage = (String) dataMap.get("message");
            res.put(ResponseMessage.RES_CODE, "-24");
            res.put(ResponseMessage.MESSAGE_IN, executeMessage);
            res.put(ResponseMessage.MESSAGE, executeMessage);
            res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
        }
        return res;
    }


    /**
     * 获取门诊收费开单记录列表
     *
     * @param channelCode   渠道编码
     * @param hospitalCode  医院编码
     * @param recordId      挂号序列
     * @param patientId     患者ID
     * @param source        挂号来源
     * @param user          用户名
     * @param payState      支付状态
     * @param clinicPayType 诊间结算类型
     * @return
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = true)
    public Map<String, Object> loadClinicOrderList(String channelCode, String hospitalCode, String recordId, String patientId, String source, String user, String payState, String clinicPayType) throws Exception {
        Map<String, Object> res = new LinkedHashMap<>();
        Map<String, Object> params = new HashMap<>(16);
        params.put("id", recordId);
        Map<String, Object> resDaoMap = clinicAppointmentRecordDao.findOne(params);
        if (resDaoMap != null) {
            params.put("patientId", patientId);
            params.put("idCard", resDaoMap.get("idCard"));
            params.put("appointDate", resDaoMap.get("appointDate"));
            params.put("tranNo", resDaoMap.get("tranNo"));
            params.put("visitNo", resDaoMap.get("visitNo"));
            Map<String, Object> resMap = new HashMap<>(16);
            String method = "send";
            Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
            Transfer transfer = new LoadClinicOrderListTransfer(method, client, "GetOrder");
            resMap = transfer.transfer(params);
            String executeMessage = (String) resMap.get("message");
            if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
                res.put("recordId", recordId);
                res.put("patientId", patientId);
                res.put("appNoList", resMap.get("appNoList"));
                res.put(ResponseMessage.RES_CODE, "0");
                res.put(ResponseMessage.MESSAGE_IN, "查询门诊收费开单记录列表成功");
                res.put(ResponseMessage.MESSAGE, "查询门诊收费开单记录列表成功");
                res.put(ResponseMessage.MESSAGE_OUT, "查询门诊收费开单记录列表成功");
            } else {
                res.put(ResponseMessage.RES_CODE, "-26");
                res.put(ResponseMessage.MESSAGE_IN, executeMessage);
                res.put(ResponseMessage.MESSAGE, executeMessage);
                res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
            }
        } else {
            res.put(ResponseMessage.RES_CODE, "-3");
            res.put(ResponseMessage.MESSAGE, "未找到 recordId 相关记录");
            res.put(ResponseMessage.MESSAGE_IN, "未找到 recordId 相关记录");
            res.put(ResponseMessage.MESSAGE_OUT, "未找到 recordId 相关记录");
        }

        return res;

    }

    /**
     * 获取诊间开单记录明细
     *
     * @param channelCode   渠道编码
     * @param hospitalCode  医院编码
     * @param recordId      挂号序列
     * @param patientId     患者ID
     * @param paySeq        处方号
     * @param source        挂号来源
     * @param user          用户名
     * @param payState      支付状态
     * @param clinicPayType 诊间结算类型
     * @return
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> loadClinicOrderDetails(String channelCode, String hospitalCode, String recordId, String patientId, String paySeq, String source, String user, String payState, String clinicPayType) throws Exception {
        Map<String, Object> res = new LinkedHashMap<>();
        Map<String, Object> params = new HashMap<>(16);
        params.put("id", recordId);
        Map<String, Object> resDaoMap = clinicAppointmentRecordDao.findOne(params);
        if (resDaoMap != null) {
            params.put("patientId", patientId);
            params.put("idCard", resDaoMap.get("idCard"));
            params.put("appointDate", resDaoMap.get("appointDate"));
            params.put("tranNo", resDaoMap.get("tranNo"));
            params.put("visitNo", resDaoMap.get("visitNo"));
            params.put("paySeq", paySeq);
            Map<String, Object> resMap = new HashMap<>(16);
            String method = "send";
            Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
            Transfer transfer = new LoadClinicOrderDetailsTransfer(method, client, "GetOrder");
            resMap = transfer.transfer(params);
            String executeMessage = (String) resMap.get("message");
            if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
                List<Map<String, Object>> chargeDetailsList = (List<Map<String, Object>>) resMap.get("chargeDetailsList");
                res.put("recordId", recordId);
                res.put("patientId", patientId);
                res.put("idCard", resDaoMap.get("idCard"));
                res.put("name", resDaoMap.get("name"));
                res.put("cardId", resDaoMap.get("cardId"));
                res.put("cardType", "");
                res.put("paySeq", paySeq);
                res.put("payState", "1");
                res.put("visitNo", resDaoMap.get("visitNo"));
                res.put("totalCost", resMap.get("totalCost"));
                res.put("chargeDetailsList", chargeDetailsList);
                for (Map<String, Object> el : chargeDetailsList) {
                    List<Map<String, Object>> costList = (List<Map<String, Object>>) el.get("costList");
                    for (Map<String, Object> subel : costList) {
                        Map<String, Object> daoParams = new HashMap<>(16);
                        daoParams.put("paySeq", paySeq);
                        Map<String, Object> findOneRes = clinicChargeRecordDao.findOne(daoParams);
                        if (findOneRes != null && ("1".equals(findOneRes.get("clinicChargeStatus")) || "3".equals(findOneRes.get("clinicChargeStatus")))) {
                            daoParams.put("clinicChargeStatus", el.get("status"));
                            daoParams.put("executionStatus", el.get("affirStatus"));
                            clinicChargeDetailsRecordDao.modifyByPaySeq(daoParams);
                        } else {
                            clinicChargeDetailsRecordDao.deleteByPaySeq(daoParams);
                            Map<String, Object> addParamas = new HashMap<>(16);
                            addParamas.put("clinicCostItemId", subel.get("clinicCostItemNo"));
                            addParamas.put("hospitalCode", hospitalCode);
                            addParamas.put("channelCode", channelCode);
                            addParamas.put("userName", user);
                            addParamas.put("recordId", recordId);
                            addParamas.put("paySeq", paySeq);
                            addParamas.put("costs", subel.get("costs"));
                            addParamas.put("parentName", subel.get("parentName"));
                            addParamas.put("charges", subel.get("charges"));
                            String inputDateTime = (String) subel.get("inputDateTime");
                            addParamas.put("inputDateTime", DataFormatUtils.parser(inputDateTime));
                            addParamas.put("units", subel.get("units"));
                            addParamas.put("usages", subel.get("usages"));
                            addParamas.put("amount", subel.get("amount"));
                            addParamas.put("itemName", subel.get("itemName"));
                            addParamas.put("itemCode", subel.get("itemCode"));
                            addParamas.put("reqId", subel.get("reqId"));
                            addParamas.put("reqClass", subel.get("reqClass"));
                            addParamas.put("doctorInsurType", subel.get("doctorInsurType"));
                            addParamas.put("clinicId", subel.get("clinicId"));
                            addParamas.put("orderedDoctorName", subel.get("orderedDoctor"));
                            addParamas.put("orderedDeptCode", subel.get("orderedDeptCode"));
                            addParamas.put("executionDeptCode", subel.get("executionDeptCode"));
                            addParamas.put("executionDeptName", subel.get("orderedByName"));
                            addParamas.put("patientId", patientId);
                            addParamas.put("itemSpec", subel.get("itemSpec"));
                            addParamas.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
                            addParamas.put("executionStatus", el.get("affirStatus"));
                            addParamas.put("clinicChargeStatus", el.get("status"));
                            clinicChargeDetailsRecordDao.add(addParamas);
                        }
                    }
                }
                res.put(ResponseMessage.RES_CODE, "0");
                res.put(ResponseMessage.MESSAGE_IN, "查询门诊收费开单记录详情成功");
                res.put(ResponseMessage.MESSAGE, "查询门诊收费开单记录详情成功");
                res.put(ResponseMessage.MESSAGE_OUT, "查询门诊收费开单记录详情成功");
            } else {
                res.put(ResponseMessage.RES_CODE, "-1");
                res.put(ResponseMessage.MESSAGE_IN, executeMessage);
                res.put(ResponseMessage.MESSAGE, executeMessage);
                res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
            }
        } else {
            res.put(ResponseMessage.RES_CODE, "-1");
            res.put(ResponseMessage.MESSAGE, "未找到 recordId 的相关记录");
            res.put(ResponseMessage.MESSAGE_IN, "未找到 recordId 的相关记录");
            res.put(ResponseMessage.MESSAGE_OUT, "未找到 recordId 的相关记录");
        }

        return res;
    }


    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = true)
    public Map<String, Object> loadAllClinicOrderList(String channelCode, String hospitalCode, String recordId, String patientId, String source, String user, String payState, String clinicPayType) throws Exception {
        Map<String, Object> res = new LinkedHashMap<>();
        Map<String, Object> params = new HashMap<>(16);
        params.put("id", recordId);
        Map<String, Object> resDaoMap = clinicAppointmentRecordDao.findOne(params);
        if (resDaoMap != null) {
            params.put("patientId", patientId);
            params.put("idCard", resDaoMap.get("idCard"));
            params.put("appointDate", resDaoMap.get("appointDate"));
            params.put("tranNo", resDaoMap.get("tranNo"));
            params.put("visitNo", resDaoMap.get("visitNo"));
            Map<String, Object> resMap = new HashMap<>(16);
            String method = "send";
            Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
            Transfer transfer = new LoadAllClinicOrderListTransfer(method, client, "GetOrder");
            resMap = transfer.transfer(params);
            String executeMessage = (String) resMap.get("message");
            if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
                res.put("recordId", recordId);
                res.put("patientId", patientId);
                res.put("appNoList", resMap.get("appNoList"));
                res.put(ResponseMessage.RES_CODE, "0");
                res.put(ResponseMessage.MESSAGE_IN, "查询门诊收费开单记录列表成功");
                res.put(ResponseMessage.MESSAGE, "查询门诊收费开单记录列表成功");
                res.put(ResponseMessage.MESSAGE_OUT, "查询门诊收费开单记录列表成功");
            } else {
                res.put(ResponseMessage.RES_CODE, "-26");
                res.put(ResponseMessage.MESSAGE_IN, executeMessage);
                res.put(ResponseMessage.MESSAGE, executeMessage);
                res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
            }
        } else {
            res.put(ResponseMessage.RES_CODE, "-3");
            res.put(ResponseMessage.MESSAGE, "未找到 recordId 相关记录");
            res.put(ResponseMessage.MESSAGE_IN, "未找到 recordId 相关记录");
            res.put(ResponseMessage.MESSAGE_OUT, "未找到 recordId 相关记录");
        }

        return res;

    }

    /**
     * 获取未支付订单
     *
     * @param channelCode  渠道编码
     * @param hospitalCode 医院编码
     * @param idCard       身份证号
     * @param source       挂号来源
     * @param user         操作用户名
     * @param orderType    订单类型:0挂号；1收费；
     * @return
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> loadUnpaidOrders(String channelCode, String hospitalCode, String idCard, String source, String user, String orderType) {
        Map<String, Object> res = new HashMap<>(16);
        List<Map<String, Object>> dataList = new ArrayList<>();

        //0：当日挂号未支付订单；3:全部类别未支付订单
        if ("0".equals(orderType) || "3".equals(orderType)) {
            Map<String, Object> registerParams = new HashMap<>(16);
            registerParams.put("channelCode", channelCode);
            registerParams.put("hospitalCode", hospitalCode);
            registerParams.put("idCard", idCard);
            registerParams.put("state", "4");
            List<Map<String, Object>> registResList = new ArrayList<>();
            registResList = clinicAppointmentRecordDao.find(registerParams);
            for (Map<String, Object> subMap : registResList) {
                Map<String, Object> resSubMap = new HashMap<>(16);
//                resSubMap.put("recordId", subMap.get("id"));
//                resSubMap.put("appointId", subMap.get("appointId"));
//                resSubMap.put("appointDate", DataFormatUtils.getTimeString((Date) subMap.get("appointDate")));
//                resSubMap.put("deptCode", subMap.get("deptCode"));
//                resSubMap.put("deptName", subMap.get("deptName"));
//                resSubMap.put("deptCode", subMap.get("deptCode"));
//                resSubMap.put("doctorCode", subMap.get("doctorCode"));
//                resSubMap.put("doctorName", subMap.get("doctorName"));
//                resSubMap.put("doctorTitleCode", subMap.get("doctorTitleCode"));
//                resSubMap.put("ampm", subMap.get("ampm"));
//                resSubMap.put("totalCost", subMap.get("totalCost"));
                resSubMap.put("recordId", subMap.get("id"));
                resSubMap.put("patientId", "");
                resSubMap.put("insurVisitId", "");
                resSubMap.put("insurPay", "");
                resSubMap.put("insurAccountPay", "");
                resSubMap.put("ownPay", "");
                resSubMap.put("inputDateTime", "");
                resSubMap.put("details", "");
                resSubMap.put("paySeq", "");
                resSubMap.put("orderType", "0");
                dataList.add(resSubMap);
            }
        }

        //1：预约报到未支付订单；3:全部类别未支付订单
        if ("1".equals(orderType) || "3".equals(orderType)) {
            Map<String, Object> appointmentParams = new HashMap<>(16);
            appointmentParams.put("channelCode", channelCode);
            appointmentParams.put("hospitalCode", hospitalCode);
            appointmentParams.put("idCard", idCard);
            appointmentParams.put("state", "5");
            List<Map<String, Object>> appointResList = new ArrayList<>();
            appointResList = clinicAppointmentRecordDao.find(appointmentParams);
            for (Map<String, Object> subMap : appointResList) {
                Map<String, Object> resSubMap = new HashMap<>(16);
//                resSubMap.put("recordId", subMap.get("id"));
//                resSubMap.put("appointId", subMap.get("appointId"));
//                resSubMap.put("appointDate", DataFormatUtils.getTimeString((Date) subMap.get("appointDate")));
//                resSubMap.put("deptCode", subMap.get("deptCode"));
//                resSubMap.put("deptName", subMap.get("deptName"));
//                resSubMap.put("deptCode", subMap.get("deptCode"));
//                resSubMap.put("doctorCode", subMap.get("doctorCode"));
//                resSubMap.put("doctorName", subMap.get("doctorName"));
//                resSubMap.put("doctorTitleCode", subMap.get("doctorTitleCode"));
//                resSubMap.put("ampm", subMap.get("ampm"));
//                resSubMap.put("totalCost", subMap.get("totalCost"));
                resSubMap.put("recordId", subMap.get("id"));
                resSubMap.put("patientId", "");
                resSubMap.put("insurVisitId", "");
                resSubMap.put("insurPay", "");
                resSubMap.put("insurAccountPay", "");
                resSubMap.put("ownPay", "");
                resSubMap.put("inputDateTime", "");
                resSubMap.put("details", "");
                resSubMap.put("orderType", "1");
                resSubMap.put("paySeq", "");
                dataList.add(resSubMap);
            }
        }

        //2：收费未支付订单；3:全部未支付订单
        if ("2".equals(orderType) || "3".equals(orderType)) {
            Map<String, Object> clinicChargrParams = new HashMap<>(16);
            clinicChargrParams.put("channelCode", channelCode);
            clinicChargrParams.put("hospitalCode", hospitalCode);
            clinicChargrParams.put("idCard", idCard);
            clinicChargrParams.put("clinicChargeStatus", "2");
            List<Map<String, Object>> clinicChargeRecordList = new ArrayList<>();
            clinicChargeRecordList = clinicChargeRecordDao.find(clinicChargrParams);
            for (Map<String, Object> subMap : clinicChargeRecordList) {
                Map<String, Object> resSubMap = new HashMap<>(16);
                String paySeq = (String) subMap.get("paySeq");
                resSubMap.put("paySeq", paySeq);
                Map<String, Object> detailsParams = new HashMap<>(16);
                detailsParams.put("paySeq", paySeq);
                detailsParams.put("channelCode", channelCode);
                detailsParams.put("hospitalCode", hospitalCode);
                List<Map<String, Object>> resDetailsList = new ArrayList<>();
                resDetailsList = clinicChargeDetailsRecordDao.find(detailsParams);
                String inputDateTime = "";
                String details = "";
//                if (resDetailsList != null) {
//                    for (Map<String, Object> detailsSubMap : resDetailsList) {
//                        List<Map<String, Object>> costList = (List<Map<String, Object>>) detailsSubMap.get("costList");
//                        for (Map<String, Object> SubMap : resDetailsList){
                inputDateTime = DataFormatUtils.getTimeString((Date) subMap.get("4"));
                details = details + " | " + subMap.get("itemName");
//                        resSubMap.put("clinicCostItemId", detailsSubMap.get("clinicCostItemNo"));
//                        resSubMap.put("hospitalCode", hospitalCode);
//                        resSubMap.put("channelCode", channelCode);
//                        resSubMap.put("userName", user);
//                        resSubMap.put("paySeq", paySeq);
//                        resSubMap.put("costs", detailsSubMap.get("costs"));
//                        resSubMap.put("parentName", detailsSubMap.get("parentName"));
//                        resSubMap.put("charges", detailsSubMap.get("charges"));
//                        resSubMap.put("units", detailsSubMap.get("units"));
//                        resSubMap.put("usages", detailsSubMap.get("usages"));
//                        resSubMap.put("amount", detailsSubMap.get("amount"));
//                        resSubMap.put("itemName", detailsSubMap.get("itemName"));
//                        resSubMap.put("itemCode", detailsSubMap.get("itemCode"));
//                        resSubMap.put("reqId", detailsSubMap.get("reqId"));
//                        resSubMap.put("reqClass", detailsSubMap.get("reqClass"));
//                        resSubMap.put("doctorInsurType", detailsSubMap.get("doctorInsurType"));
//                        resSubMap.put("clinicId", detailsSubMap.get("clinicId"));
//                        resSubMap.put("docName", detailsSubMap.get("orderedDoctor"));
//                        resSubMap.put("orderedDeptCode", detailsSubMap.get("orderedDeptCode"));
//                        resSubMap.put("executionDeptCode", detailsSubMap.get("executionDeptCode"));
//                        resSubMap.put("deptName", detailsSubMap.get("deptName"));
//                        resSubMap.put("itemSpec", detailsSubMap.get("itemSpec"));
//                        resSubMap.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
//                        resSubMap.put("executionStatus", detailsSubMap.get("affirStatus"));
//                        resSubMap.put("clinicChargeStatus", detailsSubMap.get("status"));
// //                   }
//                    }
//                }
                resSubMap.put("recordId", subMap.get("recordId"));
                resSubMap.put("patientId", subMap.get("patientId"));
                resSubMap.put("insurVisitId", "");
                resSubMap.put("insurPay", subMap.get("insurPay"));
                resSubMap.put("insurAccountPay", subMap.get("insurAccountPay"));
                resSubMap.put("ownPay", subMap.get("ownPay"));
                resSubMap.put("inputDateTime", inputDateTime);
                resSubMap.put("details", details);
                resSubMap.put("orderType", "2");
                dataList.add(resSubMap);
            }

        }

        if (dataList.size() == 0 || dataList == null) {
            res.put(ResponseMessage.RES_CODE, "-1");
            res.put(ResponseMessage.MESSAGE, "未查询到未支付订单");
            res.put(ResponseMessage.MESSAGE_IN, "未查询到未支付订单");
            res.put(ResponseMessage.MESSAGE_OUT, "未查询到未支付订单");
        } else {
            res.put("dataList", dataList);
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE, "查询未支付订单详情成功");
            res.put(ResponseMessage.MESSAGE_IN, "查询未支付订单详情成功");
            res.put(ResponseMessage.MESSAGE_OUT, "查询未支付订单详情成功");
        }


        return res;
    }

    @Override
    public Map<String, Object> doctorInfoList(String deptCode, String queryType) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        String method = "send";
        Map<String, Object> params = new HashMap<>(16);
        params.put("deptCode", deptCode);
        params.put("queryType", "1");
        params.put("hospitalCode", "0001");
        String introduce = "无";
        String titleCode = "无";
        String major = "无";
        String url = "无";
        String sex = "无";
        String deptName = "无";
        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
        Transfer transfer = new DoctorInfoListTransfer(method, client, "GetDoctorXml");
        Map<String, Object> dataMap = transfer.transfer(params);
        List<Map<String, Object>> dataList = new ArrayList<>();
        if (Dialect.getSuccessfulState().equals(dataMap.get(ResponseMessage.RES_CODE))) {
            List<Map<String, Object>> list = (List<Map<String, Object>>) dataMap.get("list");
            if (list != null && list.size() > 0) {
                for (Map<String, Object> dateSubMap : list) {
                    String deptId = (String) dateSubMap.get("deptCode");
                    if (deptId.equals("010140") || deptId.equals("010240") || deptId.equals("010340") || deptId.equals("020140") || deptId.equals("020240")) {
                        Map<String, Object> paramsMap = new HashMap<>(16);
                        {
                            paramsMap.put("deptId", dateSubMap.get("deptCode"));
                            paramsMap.put("docName", dateSubMap.get("docName"));
                            paramsMap.put("docId", dateSubMap.get("doctorCode"));
                            params.put("doctorCode", dateSubMap.get("doctorCode"));
                            Map<String, Object> resDoctorDao = doctorDao.findOne(params);
                            if (resDoctorDao != null) {
                                introduce = (String) resDoctorDao.get("introduce");
                                titleCode = (String) resDoctorDao.get("titleCode");
                                major = (String) resDoctorDao.get("major");
                                url = (String) resDoctorDao.get("iconUrl");
                                sex = (String) resDoctorDao.get("sex");
                            }
                        }
                        Map<String, Object> reshospitalDeptDao = deptDao.findOne(params);
                        if (reshospitalDeptDao != null) {
                            deptName = (String) reshospitalDeptDao.get("deptName");
                        }
                        Map<String, Object> resDoctorDao = doctorDao.findOne(params);
                        if (resDoctorDao != null) {
                            paramsMap.put("url", resDoctorDao.get("iconUrl"));
                            paramsMap.put("major", major);
                            paramsMap.put("introduction", introduce);
                            paramsMap.put("sex", sex);
                        }
                        paramsMap.put("deptName", deptName);
                        paramsMap.put("title", Dialect.getDoctorTitleName(titleCode));
                        paramsMap.put("major", major);
                        paramsMap.put("introduction", introduce);
                        paramsMap.put("sex", sex);
                        dataList.add(paramsMap);
                    }
                }

            }
            res.put("dataList", dataList);
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "查询数据成功");
            res.put(ResponseMessage.MESSAGE, "查询数据成功");
            res.put(ResponseMessage.MESSAGE_OUT, "查询数据成功");
        } else {
            String executeMessage = (String) dataMap.get("message");
            res.put(ResponseMessage.RES_CODE, "-24");
            res.put(ResponseMessage.MESSAGE_IN, executeMessage);
            res.put(ResponseMessage.MESSAGE, executeMessage);
            res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
        }

        return res;
    }

    @Override
    public Map<String, Object> doctorInfoDetails(String deptCode, String doctorCode, String queryType) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        String method = "send";
        Map<String, Object> params = new HashMap<>(16);
        params.put("deptCode", deptCode);
        params.put("doctorCode", doctorCode);
        params.put("queryType", "2");
        params.put("hospitalCode", "0001");
        String introduce = "无";
        String titleCode = "无";
        String major = "无";
        String sex = "无";
        String url = "无";
        String deptName = "无";
        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
        Transfer transfer = new DoctorInfoDetailsTransfer(method, client, "GetDoctorXml");
        Map<String, Object> dataMap = transfer.transfer(params);
        List<Map<String, Object>> dataList = new ArrayList<>();
        if (Dialect.getSuccessfulState().equals(dataMap.get(ResponseMessage.RES_CODE))) {
            List<Map<String, Object>> list = (List<Map<String, Object>>) dataMap.get("list");
            if (list != null && list.size() > 0) {
                for (Map<String, Object> dateSubMap : list) {
                    Map<String, Object> paramsMap = new HashMap<>(16);
                    {
                        paramsMap.put("deptId", dateSubMap.get("deptCode"));
//                        paramsMap.put("deptName", dateSubMap.get("deptName"));
                        paramsMap.put("docName", dateSubMap.get("docName"));
                        paramsMap.put("docId", dateSubMap.get("doctorCode"));
                        params.put("doctorCode", doctorCode);
                        Map<String, Object> resDoctorDao = doctorDao.findOne(params);
                        if (resDoctorDao != null) {
                            introduce = (String) resDoctorDao.get("introduce");
                            titleCode = (String) resDoctorDao.get("titleCode");
                            major = (String) resDoctorDao.get("major");
                            url = (String) resDoctorDao.get("iconUrl");
                            sex = (String) resDoctorDao.get("sex");
                        }
                        Map<String, Object> reshospitalDeptDao = deptDao.findOne(params);
                        if (reshospitalDeptDao != null) {
                            deptName = (String) reshospitalDeptDao.get("deptName");
                        }
                        paramsMap.put("deptName", deptName);
                        paramsMap.put("title", Dialect.getDoctorTitleName(titleCode));
                        paramsMap.put("major", major);
                        paramsMap.put("introduction", introduce);
                        paramsMap.put("sex", sex);
                        if (resDoctorDao != null) {
                            paramsMap.put("url", resDoctorDao.get("iconUrl"));
                        }
                        dataList.add(paramsMap);
                    }
                }

            }
            res.put("dataList", dataList);
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "查询数据成功");
            res.put(ResponseMessage.MESSAGE, "查询数据成功");
            res.put(ResponseMessage.MESSAGE_OUT, "查询数据成功");
        } else {
            String executeMessage = (String) dataMap.get("message");
            res.put(ResponseMessage.RES_CODE, "-24");
            res.put(ResponseMessage.MESSAGE_IN, executeMessage);
            res.put(ResponseMessage.MESSAGE, executeMessage);
            res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
        }
        return res;
    }

    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> loadSaveCharge(String channelCode, String hospitalCode, String recordId, String patientId, String paySeq, String source, String user, String payState, String clinicPayType) throws Exception {
        Map<String, Object> res = new LinkedHashMap<>();
        Map<String, Object> params = new HashMap<>(16);
        params.put("channelCode", channelCode);
        params.put("hospitalCode", hospitalCode);
        params.put("paySeq", paySeq);
        params.put("id", recordId);
        String idCard = "wu";
        String name = "wu";
        String visitNo = "wu";
//        String pay = "wu";
        Map<String, Object> resappointmentDao = clinicAppointmentRecordDao.findOne(params);
        Map<String, Object> reschargeDao = clinicChargeRecordDao.findOne(params);
        res.put("recordId", recordId);
        res.put("paySeq", paySeq);
        res.put("patientId", patientId);
        idCard = (String) resappointmentDao.get("idCard");
        name = (String) resappointmentDao.get("name");
        visitNo = (String) resappointmentDao.get("visitNo");
        int pay = (Integer) reschargeDao.get("clinicChargeStatus");
        res.put("idCard", idCard);
        res.put("name", name);
        res.put("cardType", "");
        res.put("visitNo", visitNo);
        res.put("payState", pay);
        String totalCost = "";
        List<Map<String, Object>> chargeDetailsList = new ArrayList<>();

        List<Map<String, Object>> costList = this.clinicChargeDetailsRecordDao.find(params);

//        res.put("chargeDetailsList", chargeDetailsList);
//        for (Map<String, Object> el : chargeDetailsList) {
//            String subTotalCost = (String) el.get("charges");
//            totalCost = totalCost + Double.parseDouble(subTotalCost);
//            List<Map<String, Object>> costList = this.clinicChargeDetailsRecordDao.find(params);
//            for (Map<String, Object> subel : costList) {
//                Map<String, Object> daoParams = new HashMap<>(16);
//                daoParams.put("chargeDetailsList", chargeDetailsList);
//                costList.add(daoParams);
//            }

        Map<String, Object> detailMap = new HashMap<>();
        chargeDetailsList.add(detailMap);
        BigDecimal tempDecimal = new BigDecimal(0);
        if (costList != null && costList.size() > 0) {
            detailMap.put("subCostTypeName", costList.get(0).get("reqClass"));
            detailMap.put("subCostTypeCode", "");

            for (Map<String, Object> dateSubMap : costList) {
                String subTotalCost = (String) dateSubMap.get("charges");
                tempDecimal = tempDecimal.add(new BigDecimal(subTotalCost));
                dateSubMap.put("docName", dateSubMap.get("orderedDoctorName"));
                dateSubMap.put("deptName", dateSubMap.get("executionDeptName"));
//                String inputDateTime = (String) costList.get(0).get("inputDateTime");
                dateSubMap.put("inputDateTime", dateSubMap.get("inputDateTime"));
            }
            detailMap.put("subCost", tempDecimal.doubleValue() + "");
            detailMap.put("costList", costList);
        }
        res.put("totalCost", tempDecimal.doubleValue() + "");
        res.put("chargeDetailsList", chargeDetailsList);
        res.put(ResponseMessage.RES_CODE, "0");
        res.put(ResponseMessage.MESSAGE_IN, "查询数据成功");
        res.put(ResponseMessage.MESSAGE, "查询数据成功");
        res.put(ResponseMessage.MESSAGE_OUT, "查询数据成功");
        return res;
    }

//    /**
//     * 医保信息验证
//     *
//     * @param channelCode  渠道编码
//     * @param insurNo      医保卡号
//     * @param password     密码
//     * @param idNo         身份证号
//     * @return
//     */
//    @Override
//    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
//    public Map<String, Object> insuranceInfo(String channelCode, String insurNo, String password, String idNo) throws Exception {
//        Map<String, Object> res = new HashMap<>(16);
//        String method = "send";
//        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
//        Transfer transfer = new InsuranceInfoTransfer(method, client,"GetInsuranceInfo");
//        Map<String, Object> params = new HashMap<>(16);
//        params.put("personId", idNo);
//        params.put("insurNo", insurNo);
//        Map<String, Object> respersonDao = personDao.findOne(params);
//        if (respersonDao == null) {
//            throw new DataNotFoundException("未找到身份证：" + idNo + " 的患者");
//        }
//        Map<String, Object> resultMap = transfer.transfer(params);
//        Map<String, Object> dataMap = new HashMap<>(16);
//        params.put("insurNo", insurNo);
//        if (Dialect.getSuccessfulState().equals(resultMap.get(ResponseMessage.RES_CODE))){
//            if(idNo.equals(resultMap.get("idNo"))){
//                dataMap.put("personId", resultMap.get("idNo"));
//                dataMap.put("insurNo", insurNo);
//                personDao.modify(dataMap);
//                res.put(ResponseMessage.RES_CODE, "0");
//                res.put(ResponseMessage.MESSAGE_IN, "医保卡添加成功");
//                res.put(ResponseMessage.MESSAGE, "医保卡添加成功");
//                res.put(ResponseMessage.MESSAGE_OUT, "医保卡添加成功");
//            }else{
//                res.put(ResponseMessage.RES_CODE, "-9");
//                res.put(ResponseMessage.MESSAGE_IN, "医保卡添加失败，请核对医保卡号或密码是否正确");
//                res.put(ResponseMessage.MESSAGE, "医保卡添加失败，请核对医保卡号或密码是否正确");
//                res.put(ResponseMessage.MESSAGE_OUT, "医保卡添加失败，请核对医保卡号或密码是否正确");
//            }
//        }
//        else{
//            res.put(ResponseMessage.RES_CODE, "-9");
//            res.put(ResponseMessage.MESSAGE_IN, "医保卡添加失败，请核对医保卡号或密码是否正确");
//            res.put(ResponseMessage.MESSAGE, "医保卡添加失败，请核对医保卡号或密码是否正确");
//            res.put(ResponseMessage.MESSAGE_OUT, "医保卡添加失败，请核对医保卡号或密码是否正确");
//        }
//        dataMap.put("personId", idNo);
//        dataMap.put("insurNo", insurNo);
//                this.personDao.modify(dataMap);
//                res.put(ResponseMessage.RES_CODE, "0");
//                res.put(ResponseMessage.MESSAGE_IN, "医保卡添加成功");
//                res.put(ResponseMessage.MESSAGE, "医保卡添加成功");
//                res.put(ResponseMessage.MESSAGE_OUT, "医保卡添加成功");
//        return res;
//    }

    /**
     * 医保信息验证
     *
     * @param channelCode 渠道编码
     * @param insurNo     医保卡号
     * @param password    密码
     * @param idNo        身份证号
     * @return
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> insuranceInfo(String channelCode, String insurNo, String password, String idNo) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        String method = "send";
        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
        Transfer transfer = new InsuranceInfoTransfer(method, client, "GetInsuranceInfo");
        Map<String, Object> params = new HashMap<>(16);
        params.put("personId", idNo);
        params.put("insurNo", insurNo);
        Map<String, Object> respersonDao = personDao.findOne(params);
        if (respersonDao == null) {
            throw new RuntimeException("未找到身份证：" + idNo + " 的患者");
        }
        Map<String, Object> resultMap = transfer.transfer(params);
        Map<String, Object> dataMap = new HashMap<>(16);
        params.put("insurNo", insurNo);
        if (Dialect.getSuccessfulState().equals(resultMap.get(ResponseMessage.RES_CODE))) {
            if (idNo.equals(resultMap.get("idNo"))) {
                dataMap.put("personId", resultMap.get("idNo"));
                dataMap.put("insurNo", insurNo);
                personDao.modify(dataMap);
                res.put(ResponseMessage.RES_CODE, "0");
                res.put(ResponseMessage.MESSAGE_IN, "医保卡添加成功");
                res.put(ResponseMessage.MESSAGE, "医保卡添加成功");
                res.put(ResponseMessage.MESSAGE_OUT, "医保卡添加成功");
            } else {
                res.put(ResponseMessage.RES_CODE, "-1");
                res.put(ResponseMessage.MESSAGE_IN, "医保卡添加失败，请核对医保卡号是否正确");
                res.put(ResponseMessage.MESSAGE, "医保卡添加失败，请核对医保卡号是否正确");
                res.put(ResponseMessage.MESSAGE_OUT, "医保卡添加失败，请核对医保卡号是否正确");
            }
        } else {
            res.put(ResponseMessage.RES_CODE, "-1");
            res.put(ResponseMessage.MESSAGE_IN, "医保卡添加失败，请核对医保卡号或密码是否正确");
            res.put(ResponseMessage.MESSAGE, "医保卡添加失败，请核对医保卡号或密码是否正确");
            res.put(ResponseMessage.MESSAGE_OUT, "医保卡添加失败，请核对医保卡号或密码是否正确");
        }
        return res;
    }

    /**
     * 当日挂号数据保存（医保）
     *
     * @param channelCode   渠道编码
     * @param hospitalCode  医院编码
     * @param name          姓名
     * @param gender        性别
     * @param age           年龄
     * @param clinicLabel   号表
     * @param regFee        挂号费
     * @param period        时段
     * @param usePersonId   用户使用id
     * @param idCard        身份证号
     * @param patientId     患者索引
     * @param chargeType    费别
     * @param clinicType    号类
     * @param deptCode      科室编码
     * @param doctorCode    医生编码
     * @param doctorName    医生姓名
     * @param insurNo       卡id
     * @param cardType      卡类型
     * @param payType
     * @param insuranceType
     * @param mtType
     * @return 挂号结果
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> saveRegisterInsurance(String channelCode, String hospitalCode, String name, String gender, String age, String clinicLabel, String regFee, String period, String usePersonId, String idCard, String patientId, String chargeType, String clinicType, String deptCode, String doctorCode, String doctorName, String insurNo, String cardType, String payType, String insuranceType, String mtType, String syjyxm, String bcgsbm) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> params = new HashMap<>(16);
        Map<String, Object> resultMap = new HashMap<>(16);
        String method = "send";
        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
        Transfer transfer = new SaveRegisterInsuranceTransfer(method, client, "SaveRegist");
        params.put("clinicLabel", clinicLabel);
        params.put("name", name);
        params.put("gender", gender);
        params.put("age", age);
        params.put("period", period);
        params.put("username", usePersonId);
        params.put("idCard", idCard);
        params.put("patientId", patientId);
        params.put("chargeType", chargeType);
        params.put("clinicType", Dialect.getClinicType(clinicType));
        params.put("deptCode", deptCode);
        params.put("doctorCode", doctorCode);
        params.put("doctorName", doctorName);
        params.put("cardId", insurNo);
        params.put("cardType", cardType);
        params.put("payType", payType);
        params.put("insuranceType", insuranceType);
        params.put("mtType", mtType);
        params.put("syjyxm", syjyxm);
        params.put("bcgsbm", bcgsbm);
        resultMap = transfer.transfer(params);
        String executeMessage = (String) resultMap.get("message");
        if (Dialect.getSuccessfulState().equals(resultMap.get(ResponseMessage.RES_CODE))) {
            Map<String, Object> addMap = new HashMap<>(16);
            String id = DataFormatUtils.getTimeStringNoSpace(new Date()) + hospitalCode + channelCode + IdGenerator.getSixRandNum();
            addMap.put("id", id);
            addMap.put("channelCode", channelCode);
            addMap.put("hospitalCode", hospitalCode);
            addMap.put("amount", regFee);
            addMap.put("totalCost", regFee);
            addMap.put("ampm", Dialect.getAmpmCode(period));
            addMap.put("createTime", DataFormatUtils.getTimeString(new Date()));
            addMap.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
            addMap.put("state", "4");
            addMap.put("personId", idCard);
            addMap.put("idCard", idCard);
            addMap.put("name", name);
            addMap.put("phone", usePersonId);
            addMap.put("cardId", insurNo);
            addMap.put("cardType", cardType);
            addMap.put("tranNo", resultMap.get("tranNo"));
            addMap.put("patientType", chargeType);
            addMap.put("appointDate", resultMap.get("visitDate"));
            addMap.put("deptCode", deptCode);
            addMap.put("doctorCode", doctorCode);
            addMap.put("doctorTitleCode", clinicType);
            //"3"当日挂号
            addMap.put("appointmentType", "3");
            addMap.put("visitNo", resultMap.get("visitNo"));
            addMap.put("rcptNo", resultMap.get("rcptNo"));
            addMap.put("clinicLabel", clinicLabel);
            addMap.put("username", usePersonId);
            addMap.put("insurVisitId", resultMap.get("insurVisitId"));
            addMap.put("insurPay", resultMap.get("insurPay"));
            addMap.put("insurAccountPay", resultMap.get("accountPay"));
            addMap.put("ownPay", resultMap.get("ownPay"));
            addMap.put("payType", payType);
            addMap.put("insuranceType", insuranceType);
            addMap.put("mtType", mtType);
            addMap.put("syjyxm", syjyxm);
            addMap.put("bcgsbm", bcgsbm);
            clinicAppointmentRecordDao.add(addMap);
            res.put("recordId", id);
            res.put("channelCode", channelCode);
            res.put("subject", "挂号费");
            res.put("insurVisitId", resultMap.get("insurVisitId"));
            res.put("insurPay", resultMap.get("insurPay"));
            res.put("insurAccountPay", resultMap.get("accountPay"));
            res.put("ownPay", resultMap.get("ownPay"));
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "当日挂号数据保存成功");
            res.put(ResponseMessage.MESSAGE, "当日挂号数据保存成功");
            res.put(ResponseMessage.MESSAGE_OUT, "当日挂号数据保存成功");
        } else {
            res.put(ResponseMessage.RES_CODE, "-22");
            res.put(ResponseMessage.MESSAGE_IN, executeMessage);
            res.put(ResponseMessage.MESSAGE, executeMessage);
            res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
        }
        return res;
    }

    @Override
    public Map<String, Object> loadDeptInsurance(String channelCode) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        String method = "send";
        Map<String, Object> params = new HashMap<>(16);
        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
        Transfer transfer = new LoadDeptInsuranceTransfer(method, client, "GetDepartmentXml");
        Map<String, Object> dataMap = transfer.transfer(params);
        List<Map<String, Object>> dataList = new ArrayList<>();
        if (Dialect.getSuccessfulState().equals(dataMap.get(ResponseMessage.RES_CODE))) {
            List<Map<String, Object>> list = (List<Map<String, Object>>) dataMap.get("list");
            if (list != null && list.size() > 0) {
                for (Map<String, Object> dateSubMap : list) {
                    Map<String, Object> paramsMap = new HashMap<>(16);
                    {
                        paramsMap.put("deptCode", dateSubMap.get("deptCode"));
                        paramsMap.put("deptName", dateSubMap.get("deptName"));
                        paramsMap.put("deptLocation", dateSubMap.get("deptLocation"));
                        paramsMap.put("upperDeptCode", dateSubMap.get("upperDeptCode"));
                        paramsMap.put("upperDeptName", dateSubMap.get("upperDeptName"));
                        paramsMap.put("mtType", dateSubMap.get("mtType"));
                        dataList.add(paramsMap);
                    }
                }
                res.put("dataList", dataList);
                res.put(ResponseMessage.RES_CODE, "0");
                res.put(ResponseMessage.MESSAGE_IN, "查询数据成功");
                res.put(ResponseMessage.MESSAGE, "查询数据成功");
                res.put(ResponseMessage.MESSAGE_OUT, "查询数据成功");
            }
        } else {
            String executeMessage = (String) dataMap.get("message");
            res.put(ResponseMessage.RES_CODE, "-24");
            res.put(ResponseMessage.MESSAGE_IN, executeMessage);
            res.put(ResponseMessage.MESSAGE, executeMessage);
            res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
        }
        return res;
    }

    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> saveclinicChargeDataInsurance(String channelCode, String hospitalCode, String userName, String recordId, String idCard, String resDate, String transactNo, String patientId, String visitNo, String paySeq, String cardType, String cardNumber, String payType, String insuranceType, String mtType, String insurNo, String syjyxm) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> resMap = new HashMap<>(16);
        Map<String, Object> findparams = new HashMap<>(16);
        findparams.put("paySeq", paySeq);
        findparams.put("channelCode", channelCode);
        findparams.put("hospitalCode", hospitalCode);
        findparams.put("clinicChargeStatus", "0");
        findparams.put("id", recordId);
        Map<String, Object> cliniMap = clinicAppointmentRecordDao.findOne(findparams);
        List<Map<String, Object>> costList = clinicChargeDetailsRecordDao.find(findparams);
        if (costList.size() != 0) {
            String method = "send";
            Map<String, Object> params = new HashMap<>(16);
            params.put("paySeq", paySeq);
            params.put("idCard", idCard);
            params.put("resDate", resDate);
            params.put("transactNo", transactNo);
            params.put("patientId", patientId);
            params.put("visitNo", visitNo);
            params.put("costList", costList);
            params.put("payType", payType);
            params.put("insuranceType", insuranceType);
            params.put("mtType", mtType);
            params.put("insurNo", insurNo);
            params.put("syjyxm", syjyxm);
            params.put("insurVisitId", cliniMap.get("insurVisitId"));
            params.put("rcptNo", cliniMap.get("rcptNo"));//合并增加
            Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
            Transfer transfer = new SaveclinicChargeDataInsuranceTransfer(method, client, "SaveMultiCharge");
            resMap = transfer.transfer(params);
            String executeMessage = (String) resMap.get("message");
            if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
                Map<String, Object> saveDaoParams = new HashMap<>(16);
                saveDaoParams.put("paySeq", paySeq);
                saveDaoParams.put("idCard", idCard);
                saveDaoParams.put("hospitalCode", hospitalCode);
                saveDaoParams.put("clinicChargeStatus", 2);
                saveDaoParams.put("channelCode", channelCode);
                saveDaoParams.put("userName", userName);
                saveDaoParams.put("recordId", recordId);
                saveDaoParams.put("patientId", patientId);
                saveDaoParams.put("insurPay", resMap.get("insurPay"));
                saveDaoParams.put("insurAccountPay", resMap.get("accountPay"));
                saveDaoParams.put("ownPay", resMap.get("ownPay"));
                saveDaoParams.put("rcptNo", resMap.get("rcptNo"));
                saveDaoParams.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
                saveDaoParams.put("tranNo", resMap.get("tranNo"));
                saveDaoParams.put("insurVisitId", resMap.get("insurVisitId"));
                saveDaoParams.put("idCard", idCard);
                saveDaoParams.put("payType", payType);
                saveDaoParams.put("insuranceType", insuranceType);
                saveDaoParams.put("mtType", mtType);
                saveDaoParams.put("insurNo", insurNo);
                saveDaoParams.put("syjyxm", syjyxm);
//                saveDaoParams.put("winNo", "");
                clinicChargeRecordDao.duplicateAdd(saveDaoParams);
                res.putAll(resMap);
                res.remove("rcptNo");
                res.put("recordId", recordId);
                res.put("paySeq", paySeq);
                res.put("insurPay", resMap.get("insurPay"));
                res.put("accountPay", resMap.get("accountPay"));
                res.put("ownPay", resMap.get("ownPay"));
                res.put("patientId", patientId);
                res.put(ResponseMessage.RES_CODE, "0");
                res.put(ResponseMessage.MESSAGE_IN, "缴费数据保存成功");
                res.put(ResponseMessage.MESSAGE, "缴费数据保存成功");
                res.put(ResponseMessage.MESSAGE_OUT, "缴费数据保存成功");
            } else {
                res.put(ResponseMessage.RES_CODE, "-28");
                res.put(ResponseMessage.MESSAGE_IN, executeMessage);
                res.put(ResponseMessage.MESSAGE, executeMessage);
                res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
            }
        } else {
            res.put(ResponseMessage.RES_CODE, "-3");
            res.put(ResponseMessage.MESSAGE, "未找到 paySeq 的相关记录");
            res.put(ResponseMessage.MESSAGE_IN, "未找到 paySeq 的相关记录");
            res.put(ResponseMessage.MESSAGE_OUT, "未找到 paySeq 的相关记录");
        }
        return res;
    }


    /**
     * 预约报道(yibao)
     *
     * @param channelCode         渠道编码
     * @param hospitalCode        医院编码
     * @param appointmentCode     预约编码
     * @param hisClinicAppointsId HIS预约ID
     * @param userPersonId        挂号用户id
     * @param recordId            挂号ID
     * @return 预约报道结果
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> checkAppointmentStateInsurance(String channelCode, String hospitalCode, String appointmentCode, String hisClinicAppointsId, String patientId, String userPersonId, String recordId, String insurNo, String insuranceType, String payType, String mtType, String syjyxm, String bcgsbm) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        String method = "send";
        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
        Transfer transfer = new CheckAppointmentStateInsuranceTransfer(method, client, "AppointSignIn");
        Map<String, Object> params = new HashMap<>(16);
        params.put("hisClinicAppointsId", hisClinicAppointsId);
        params.put("patientId", patientId);
        params.put("chargeType", "");
        params.put("idCard", userPersonId);
        params.put("insurNo", insurNo);
        params.put("insuranceType", insuranceType);
        params.put("payType", payType);
        params.put("mtType", mtType);
        params.put("syjyxm", syjyxm);
        params.put("bcgsbm", bcgsbm);
        Map<String, Object> resMap = transfer.transfer(params);
        if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
            res.put("ifPay", "0");
            res.put("subject", "挂号费");
            res.put("insurPay", resMap.get("insurPay"));
            res.put("ownPay", resMap.get("ownPay"));
            res.put("accountPay", resMap.get("accountPay"));
            res.put("recordId", recordId);
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "成功");
            res.put(ResponseMessage.MESSAGE, "成功");
            res.put(ResponseMessage.MESSAGE_OUT, "成功");
            Map<String, Object> modifyParam = new HashMap(16);
            modifyParam.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
            modifyParam.put("visitNo", resMap.get("visitNo"));
            modifyParam.put("rcptNo", resMap.get("rcptNo"));
            modifyParam.put("tranNo", resMap.get("tranNo"));
            modifyParam.put("insurVisitId", resMap.get("insurVisitId"));
            modifyParam.put("insurPay", resMap.get("insurPay"));
            modifyParam.put("insurAccountPay", resMap.get("accountPay"));
            modifyParam.put("ownPay", resMap.get("ownPay"));
            modifyParam.put("hisClinicAppointsId", hisClinicAppointsId);
            modifyParam.put("state", "5");
            modifyParam.put("totalCost", resMap.get("clinicCharge"));
            modifyParam.put("id", recordId);
            modifyParam.put("cardId", insurNo);
            modifyParam.put("insuranceType", insuranceType);
            modifyParam.put("payType", payType);
            modifyParam.put("mtType", mtType);
            modifyParam.put("syjyxm", syjyxm);
            modifyParam.put("bcgsbm", bcgsbm);
            modifyParam.put("appointId", appointmentCode);
            clinicAppointmentRecordDao.modify(modifyParam);
        } else {
            String executeMessage = (String) resMap.get("message");
            res.put(ResponseMessage.RES_CODE, "-16");
            res.put(ResponseMessage.MESSAGE_IN, executeMessage);
            res.put(ResponseMessage.MESSAGE, executeMessage);
            res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
        }
        return res;
    }

    /**
     * @param channelCode
     * @param hospitalCode
     * @param recordId     挂号ID
     * @param patientId
     * @return 当日挂号交易撤销(yibao)
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> canceleRegisterTransactionInsurance(String channelCode, String hospitalCode, String recordId, String patientId) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        String method = "send";
        Map<String, Object> params = new HashMap<>(16);
        params.put("channelCode", channelCode);
        params.put("hospitalCode", hospitalCode);
        params.put("id", recordId);
        Map<String, Object> recordMap = clinicAppointmentRecordDao.findOne(params);
        if (recordMap != null) {
            recordMap.put("patientId", patientId);

            Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
            Transfer transfer = new CanceleRegisterTransactionInsuranceTransfer(method, client, "TranCancel");
            Map<String, Object> resMap = transfer.transfer(recordMap);
            if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
                params.put("state", "7");
                clinicAppointmentRecordDao.modify(params);
                res.putAll(resMap);
                res.put(ResponseMessage.RES_CODE, "0");
                res.put(ResponseMessage.MESSAGE_IN, "当日挂号交易撤销成功");
                res.put(ResponseMessage.MESSAGE, "当日挂号交易撤销成功");
                res.put(ResponseMessage.MESSAGE_OUT, "当日挂号交易撤销成功");
            } else {
                String executeMessage = (String) resMap.get("message");
                res.put(ResponseMessage.RES_CODE, "-1");
                res.put(ResponseMessage.MESSAGE_IN, executeMessage);
                res.put(ResponseMessage.MESSAGE, executeMessage);
                res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
            }
        } else {
            res.put(ResponseMessage.RES_CODE, "-3");
            res.put(ResponseMessage.MESSAGE, "未找到相关记录");
            res.put(ResponseMessage.MESSAGE_IN, "未找到相关记录");
            res.put(ResponseMessage.MESSAGE_OUT, "未找到相关记录");
        }

        return res;
    }

    /**
     * @param channelCode
     * @param hospitalCode
     * @param recordId     挂号ID
     * @return 预约报到交易撤销(yiabo)
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> canceleAppointTransactionInsurance(String channelCode, String hospitalCode, String recordId, String patientId) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        String method = "send";
        Map<String, Object> params = new HashMap<>(16);
        params.put("channelCode", channelCode);
        params.put("id", recordId);
        Map<String, Object> recordMap = clinicAppointmentRecordDao.findOne(params);
        if (recordMap != null) {
            recordMap.put("patientId", patientId);
            Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
            Transfer transfer = new CanceleAppointTransactionInsuranceTransfer(method, client, "TranCancel");
            Map<String, Object> resMap = transfer.transfer(recordMap);
            if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
                params.put("state", "0");
                clinicAppointmentRecordDao.modify(params);
                res.putAll(resMap);
                res.put(ResponseMessage.RES_CODE, "0");
                res.put(ResponseMessage.MESSAGE_IN, "预约报到交易撤销成功");
                res.put(ResponseMessage.MESSAGE, "预约报到交易撤销成功");
                res.put(ResponseMessage.MESSAGE_OUT, "预约报到交易撤销成功");
            } else {
                String executeMessage = (String) resMap.get("message");
                res.put(ResponseMessage.RES_CODE, "0");
                res.put(ResponseMessage.MESSAGE_IN, executeMessage);
                res.put(ResponseMessage.MESSAGE, executeMessage);
                res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
            }
        } else {
            res.put(ResponseMessage.RES_CODE, "-3");
            res.put(ResponseMessage.MESSAGE, "未找到相关记录");
            res.put(ResponseMessage.MESSAGE_IN, "未找到相关记录");
            res.put(ResponseMessage.MESSAGE_OUT, "未找到相关记录");
        }

        return res;
    }

    /**
     * 诊间结算支付撤销(yibao)
     *
     * @param channelCode  渠道编码
     * @param hospitalCode 医院编码
     * @param recordId     挂号序列
     * @param patientId    患者ID
     * @param paySeq       支付序号
     * @return
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> canceleClinicChargePaymentInsurance(String channelCode, String hospitalCode, String recordId, String patientId, String paySeq) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        String method = "send";
        Map<String, Object> params = new HashMap<>(16);
        params.put("channelCode", channelCode);
        params.put("id", recordId);
        Map<String, Object> recordMap = clinicAppointmentRecordDao.findOne(params);
        if (recordMap != null) {
            Map<String, Object> subMap = new HashMap<>(16);
            subMap.put("paySeq", paySeq);
            subMap.put("hospitalCode", hospitalCode);
            Map<String, Object> subMapRes = clinicChargeRecordDao.findOne(subMap);
            if (subMapRes != null) {
                recordMap.put("patientId", patientId);
                recordMap.put("rcptNo", subMapRes.get("rcptNo"));
                recordMap.put("insuranceType", subMapRes.get("insuranceType"));
                recordMap.put("insurNo", subMapRes.get("insurNo"));
                recordMap.put("syjyxm", subMapRes.get("syjyxm"));
                Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
                Transfer transfer = new CanceleClinicChargePaymentInsuranceTransfer(method, client, "ChargeMultiCancel");
                Map<String, Object> resMap = transfer.transfer(recordMap);
                if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
                    recordMap.remove("rcptNo");
                    recordMap.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
                    recordMap.put("clinicChargeStatus", 0);
                    recordMap.put("paySeq", paySeq);
                    recordMap.put("hospitalCode", hospitalCode);
                    clinicChargeRecordDao.modifyByPaySeq(recordMap);
                    res.putAll(resMap);
                    res.put(ResponseMessage.RES_CODE, "0");
                    res.put(ResponseMessage.MESSAGE_IN, "诊间支付交易撤销成功");
                    res.put(ResponseMessage.MESSAGE, "诊间支付交易撤销成功");
                    res.put(ResponseMessage.MESSAGE_OUT, "诊间支付交易撤销成功");
                } else {
                    String executeMessage = (String) resMap.get("message");
                    if ("该笔已正常缴费，不能进行撤销!".equals(executeMessage)) {
                        recordMap.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
                        recordMap.put("clinicChargeStatus", 1);
                        recordMap.put("paySeq", paySeq);
                        recordMap.put("hospitalCode", hospitalCode);
                        clinicChargeRecordDao.modifyByPaySeq(recordMap);
                    }
                    res.put(ResponseMessage.RES_CODE, "0");
                    res.put(ResponseMessage.MESSAGE_IN, executeMessage);
                    res.put(ResponseMessage.MESSAGE, executeMessage);
                    res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
                }
            } else {
                res.put(ResponseMessage.RES_CODE, "-3");
                res.put(ResponseMessage.MESSAGE, "未找到 paySeq 相关记录");
                res.put(ResponseMessage.MESSAGE_IN, "未找到 paySeq 相关记录");
                res.put(ResponseMessage.MESSAGE_OUT, "未找到 paySeq 相关记录");
            }
        } else {
            res.put(ResponseMessage.RES_CODE, "-3");
            res.put(ResponseMessage.MESSAGE, "未找到 recordId 相关记录");
            res.put(ResponseMessage.MESSAGE_IN, "未找到 recordId 相关记录");
            res.put(ResponseMessage.MESSAGE_OUT, "未找到 recordId 相关记录");
        }

        return res;
    }


    /**
     * 预约报道支付确认接口(提供给支付平台支付完成之后回调)(yiabo)
     *
     * @param channelCode  渠道编码
     * @param hospitalCode 医院编码
     * @param recordId     挂号ID
     * @param openId       支付用户唯一ID：微信用户唯一ID、支付宝用户唯一ID、银行卡号
     * @param orderId      订单ID
     * @param patientId    患者ID
     * @param userPersonId 用户ID
     * @param orderFee     支付金额
     * @param payTime      支付时间
     * @param payType      支付类别
     * @param tradeNo      交易流水
     * @return
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> payConfirmForAppointmentInsurance(String channelCode, String hospitalCode, String recordId, String openId, String orderId, String patientId, String userPersonId, String orderFee, String payTime, String payType, String tradeNo, String moneyPay) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> params = new HashMap<>(16);
        Map<String, Object> daoRes = new HashMap<>(16);
        params.put("channelCode", channelCode);
        params.put("id", recordId);
        daoRes = clinicAppointmentRecordDao.findOne(params);
        String registStatus = (String) daoRes.get("state");
        if (daoRes != null) {
            Map<String, Object> resMap = new HashMap<>(16);
            String method = "send";
            Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
            Transfer transfer = new PayConfirmForAppointmentInsuranceTransfer(method, client, "AppointTranConfirm");
            params.putAll(daoRes);
            params.put("patientId", patientId);
            params.put("orderFee", orderFee);
            params.put("tradeNo", tradeNo);
            params.put("payType", payType);
            params.put("moneyPay", moneyPay);
            params.put("cardId", daoRes.get("cardId"));
            resMap = transfer.transfer(params);
            if (!registStatus.equals("2")) {
                if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
                    Map<String, Object> billParams = new HashMap<>(16);
                    Map<String, Object> daoParams = new HashMap<>(16);
                    res.putAll(resMap);
                    res.put(ResponseMessage.RES_CODE, "0");
                    res.put(ResponseMessage.MESSAGE_IN, "预约报道支付确认成功");
                    res.put(ResponseMessage.MESSAGE, "预约报道支付确认成功");
                    res.put(ResponseMessage.MESSAGE_OUT, "预约报道支付确认成功");
                    daoParams.put("channelCode", channelCode);
                    daoParams.put("tranNo", res.get("tranNo"));
                    daoParams.put("state", "2");
                    daoParams.put("id", recordId);
                    daoParams.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
                    clinicAppointmentRecordDao.modify(daoParams);
                    Map<String, Object> findOneRes = clinicAppointmentRecordDao.findOne(daoParams);
                    billParams.put("billId", orderId);
                    billParams.put("hospitalCode", hospitalCode);
                    billParams.put("doctorCode", findOneRes.get("doctorCode"));
                    billParams.put("deptCode", findOneRes.get("deptCode"));
                    billParams.put("appointmentCode", recordId);
                    billParams.put("appointDate", DataFormatUtils.getTimeString((Date) findOneRes.get("appointDate")));
                    billParams.put("transactNo", res.get("tranNo"));
                    billParams.put("orderId", findOneRes.get("rcptNo"));
                    billParams.put("patientId", patientId);
                    billParams.put("visitNo", findOneRes.get("visitNo"));
                    billParams.put("prescriptionNum", "");
                    billParams.put("channelCode", channelCode);
                    billParams.put("personId", findOneRes.get("personId"));
                    billParams.put("idCard", findOneRes.get("idCard"));
                    billParams.put("personName", findOneRes.get("name"));
                    billParams.put("phone", userPersonId);
                    billParams.put("username", userPersonId);
                    billParams.put("cardType", payType);
                    billParams.put("cardNum", openId);
                    billParams.put("patientType", findOneRes.get("patientType"));
                    billParams.put("totalCost", findOneRes.get("totalCost"));
                    billParams.put("tradeNo", tradeNo);
                    billParams.put("cost", orderFee);
                    billParams.put("insuranceAmount", findOneRes.get("insurPay"));
                    billParams.put("personalAmount", findOneRes.get("insurAccountPay"));
                    billParams.put("otherAmount", orderFee);
                    billParams.put("payWay", payType);
                    billParams.put("visitDate", DataFormatUtils.getTimeString((Date) findOneRes.get("appointDate")));
                    billParams.put("createTime", DataFormatUtils.getTimeString(new Date()));
                    billParams.put("payTime", payTime);
                    billParams.put("billTypeCode", "0");
                    billParams.put("payType", payType);
                    billParams.put("state", "0");
                    billingRecordDao.add(billParams);
                } else {
                    Map<String, Object> billParams = new HashMap<>(16);
                    Map<String, Object> daoParams = new HashMap<>(16);
                    daoParams.put("id", recordId);
                    Map<String, Object> findOneRes = clinicAppointmentRecordDao.findOne(daoParams);
                    billParams.put("billId", orderId);
                    billParams.put("hospitalCode", hospitalCode);
                    billParams.put("doctorCode", findOneRes.get("doctorCode"));
                    billParams.put("deptCode", findOneRes.get("deptCode"));
                    billParams.put("appointmentCode", recordId);
                    billParams.put("appointDate", DataFormatUtils.getTimeString((Date) findOneRes.get("appointDate")));
                    billParams.put("transactNo", res.get("tranNo"));
                    billParams.put("orderId", findOneRes.get("rcptNo"));
                    billParams.put("patientId", patientId);
                    billParams.put("visitNo", findOneRes.get("visitNo"));
                    billParams.put("prescriptionNum", "");
                    billParams.put("channelCode", channelCode);
                    billParams.put("personId", findOneRes.get("personId"));
                    billParams.put("idCard", findOneRes.get("idCard"));
                    billParams.put("personName", findOneRes.get("name"));
                    billParams.put("phone", userPersonId);
                    billParams.put("username", userPersonId);
                    billParams.put("cardType", payType);
                    billParams.put("cardNum", openId);
                    billParams.put("patientType", findOneRes.get("patientType"));
                    billParams.put("totalCost", findOneRes.get("totalCost"));
                    billParams.put("tradeNo", tradeNo);
                    billParams.put("cost", orderFee);
                    billParams.put("insuranceAmount", findOneRes.get("insurPay"));
                    billParams.put("personalAmount", findOneRes.get("insurAccountPay"));
                    billParams.put("otherAmount", orderFee);
                    billParams.put("payWay", payType);
                    billParams.put("visitDate", DataFormatUtils.getTimeString((Date) findOneRes.get("appointDate")));
                    billParams.put("createTime", DataFormatUtils.getTimeString(new Date()));
                    billParams.put("payTime", payTime);
                    billParams.put("billTypeCode", "0");
                    billParams.put("payType", payType);
                    billParams.put("state", "3");
                    billingRecordDao.add(billParams);
                    String executeMessage = (String) resMap.get("message");
                    res.put(ResponseMessage.RES_CODE, "-21");
                    res.put(ResponseMessage.MESSAGE_IN, executeMessage);
                    res.put(ResponseMessage.MESSAGE, executeMessage);
                    res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
                }
            } else {
                res.put(ResponseMessage.RES_CODE, "0");
                res.put(ResponseMessage.MESSAGE, "成功");
                res.put(ResponseMessage.MESSAGE_IN, "成功");
                res.put(ResponseMessage.MESSAGE_OUT, "成功");
            }
        } else {
            res.put(ResponseMessage.RES_CODE, "-3");
            res.put(ResponseMessage.MESSAGE, "未找到相关记录");
            res.put(ResponseMessage.MESSAGE_IN, "未找到相关记录");
            res.put(ResponseMessage.MESSAGE_OUT, "未找到相关记录");
        }
        return res;
    }


    /**
     * 诊间结算支付确认(yibao)
     *
     * @param channelCode  渠道编码
     * @param hospitalCode 医院编码
     * @param paySeq       支付序号
     * @param openId       支付用户唯一ID：微信用户唯一ID、支付宝用户唯一ID、银行卡号
     * @param orderId      订单ID
     * @param patientId    患者ID
     * @param userPersonId 用户ID
     * @param orderFee     支付金额
     * @param payTime      支付时间
     * @param moneyPay     支付类别
     * @param tradeNo      交易流水
     * @return
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> payConfirmForClinicChargeInsurance(String channelCode, String hospitalCode, String paySeq, String openId, String orderId, String patientId, String userPersonId, String orderFee, String payTime, String tradeNo, String moneyPay) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> params = new HashMap<>(16);
        Map<String, Object> daoRes = new HashMap<>(16);
        params.put("hospitalCode", hospitalCode);
        params.put("paySeq", paySeq);
        daoRes = clinicChargeRecordDao.findOne(params);
        if (daoRes != null) {
            params.put("id", daoRes.get("recordId"));
            Map<String, Object> registRecord = clinicAppointmentRecordDao.findOne(params);
            if (registRecord != null) {
                Map<String, Object> resMap = new HashMap<>(16);
                String method = "send";
                Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
                Transfer transfer = new PayConfirmForClinicChargeInsuranceTransfer(method, client, "ChargeMultiConfirm");
                params.put("idCard", registRecord.get("idCard"));
                params.put("patientId", patientId);
                params.put("visitNo", registRecord.get("visitNo"));
                params.put("appointDate", registRecord.get("appointDate"));
                params.put("rcptNo", daoRes.get("rcptNo"));
                params.put("tranNo", daoRes.get("tranNo"));
                params.put("tradeNo", tradeNo);
                params.put("patientId", patientId);
                params.put("orderFee", orderFee);
                params.put("payType", daoRes.get("payType"));
                params.put("moneyPay", moneyPay);
                params.put("mtType", daoRes.get("mtType"));
                params.put("insurPay", daoRes.get("insurPay"));
                params.put("accountPay", daoRes.get("insurAccountPay"));
                params.put("ownPay", daoRes.get("ownPay"));
                params.put("insuranceType", daoRes.get("insuranceType"));
                params.put("insurVisitId", registRecord.get("insurVisitId"));
                params.put("insurNo", daoRes.get("insurNo"));
                resMap = transfer.transfer(params);
                String executeMessage = (String) resMap.get("message");
                if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
                    Map<String, Object> daoParams = new HashMap<>(16);
                    Map<String, Object> billParams = new HashMap<>(16);
                    String tranNo = (String) resMap.get("tranNo");
                    res.putAll(resMap);
                    res.put(ResponseMessage.RES_CODE, "0");
                    res.put(ResponseMessage.MESSAGE_IN, "诊间缴费支付确认成功");
                    res.put(ResponseMessage.MESSAGE, "诊间缴费支付确认成功");
                    res.put(ResponseMessage.MESSAGE_OUT, "诊间缴费支付确认成功");
                    daoParams.put("paySeq", paySeq);
                    daoParams.put("hospitalCode", hospitalCode);
                    daoParams.put("clinicChargeStatus", "1");
                    daoParams.put("tranNo", resMap.get("tranNo"));
                    daoParams.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
                    daoParams.put("winNo", resMap.get("winNo"));
                    clinicChargeRecordDao.modifyByPaySeq(daoParams);
                    daoParams.put("id", daoRes.get("recordId"));
                    Map<String, Object> findOneRes = clinicAppointmentRecordDao.findOne(daoParams);
                    billParams.put("billId", orderId);
                    billParams.put("hospitalCode", hospitalCode);
                    billParams.put("doctorCode", findOneRes.get("doctorCode"));
                    billParams.put("deptCode", findOneRes.get("deptCode"));
                    billParams.put("appointmentCode", daoRes.get("recordId"));
                    billParams.put("appointDate", DataFormatUtils.getTimeString((Date) findOneRes.get("appointDate")));
                    billParams.put("transactNo", resMap.get("tranNo"));
                    billParams.put("orderId", daoRes.get("rcptNo"));
                    billParams.put("patientId", patientId);
                    billParams.put("visitNo", findOneRes.get("visitNo"));
                    billParams.put("prescriptionNum", "");
                    billParams.put("channelCode", channelCode);
                    billParams.put("personId", findOneRes.get("personId"));
                    billParams.put("idCard", findOneRes.get("idCard"));
                    billParams.put("personName", findOneRes.get("name"));
                    billParams.put("phone", userPersonId);
                    billParams.put("username", userPersonId);
                    billParams.put("cardType", "");
                    billParams.put("cardNum", openId);
                    billParams.put("patientType", findOneRes.get("patientType"));
                    billParams.put("totalCost", findOneRes.get("totalCost"));
                    billParams.put("tradeNo", tradeNo);
                    billParams.put("cost", orderFee);
                    billParams.put("insuranceAmount", findOneRes.get("insurPay"));
                    billParams.put("personalAmount", findOneRes.get("insurAccountPay"));
                    billParams.put("otherAmount", orderFee);
                    billParams.put("payWay", "");
                    billParams.put("visitDate", DataFormatUtils.getTimeString((Date) findOneRes.get("appointDate")));
                    billParams.put("createTime", DataFormatUtils.getTimeString(new Date()));
                    billParams.put("payTime", payTime);
                    billParams.put("billTypeCode", "2");
                    billParams.put("payType", "");
                    billParams.put("state", "0");
                    billingRecordDao.add(billParams);
                } else {
                    Map<String, Object> daoParams = new HashMap<>(16);
                    daoParams.put("id", daoRes.get("recordId"));
                    Map<String, Object> billParams = new HashMap<>(16);
                    Map<String, Object> findOneRes = clinicAppointmentRecordDao.findOne(daoParams);
                    billParams.put("billId", orderId);
                    billParams.put("hospitalCode", hospitalCode);
                    billParams.put("doctorCode", findOneRes.get("doctorCode"));
                    billParams.put("deptCode", findOneRes.get("deptCode"));
                    billParams.put("appointmentCode", daoRes.get("recordId"));
                    billParams.put("appointDate", DataFormatUtils.getTimeString((Date) findOneRes.get("appointDate")));
                    billParams.put("transactNo", resMap.get("tranNo"));
                    billParams.put("orderId", daoRes.get("rcptNo"));
                    billParams.put("patientId", patientId);
                    billParams.put("visitNo", findOneRes.get("visitNo"));
                    billParams.put("prescriptionNum", "");
                    billParams.put("channelCode", channelCode);
                    billParams.put("personId", findOneRes.get("personId"));
                    billParams.put("idCard", findOneRes.get("idCard"));
                    billParams.put("personName", findOneRes.get("name"));
                    billParams.put("phone", userPersonId);
                    billParams.put("username", userPersonId);
                    billParams.put("cardType", "");
                    billParams.put("cardNum", openId);
                    billParams.put("patientType", findOneRes.get("patientType"));
                    billParams.put("totalCost", findOneRes.get("totalCost"));
                    billParams.put("tradeNo", tradeNo);
                    billParams.put("cost", orderFee);
                    billParams.put("insuranceAmount", findOneRes.get("insurPay"));
                    billParams.put("personalAmount", findOneRes.get("insurAccountPay"));
                    billParams.put("otherAmount", orderFee);
                    billParams.put("payWay", "");
                    billParams.put("visitDate", DataFormatUtils.getTimeString((Date) findOneRes.get("appointDate")));
                    billParams.put("createTime", DataFormatUtils.getTimeString(new Date()));
                    billParams.put("payTime", payTime);
                    billParams.put("billTypeCode", "2");
                    billParams.put("payType", "");
                    billParams.put("state", "3");
                    billingRecordDao.add(billParams);
                    res.put(ResponseMessage.RES_CODE, "-23");
                    res.put(ResponseMessage.MESSAGE_IN, executeMessage);
                    res.put(ResponseMessage.MESSAGE, executeMessage);
                    res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
                }
            } else {
                res.put(ResponseMessage.RES_CODE, "-3");
                res.put(ResponseMessage.MESSAGE, "未找到 recordId 相关记录");
                res.put(ResponseMessage.MESSAGE_IN, "未找到 recordId 相关记录");
                res.put(ResponseMessage.MESSAGE_OUT, "未找到 recordId 相关记录");
            }
        } else {
            res.put(ResponseMessage.RES_CODE, "-3");
            res.put(ResponseMessage.MESSAGE, "未找到 paySeq 相关记录");
            res.put(ResponseMessage.MESSAGE_IN, "未找到 paySeq 相关记录");
            res.put(ResponseMessage.MESSAGE_OUT, "未找到 paySeq 相关记录");
        }
        return res;
    }

    /**
     * 挂号支付确认接口(提供给支付平台支付完成之后回调)(yibao)
     *
     * @param channelCode  渠道编码
     * @param hospitalCode 医院编码
     * @param recordId     挂号ID
     * @param openId       支付用户唯一ID：微信用户唯一ID、支付宝用户唯一ID、银行卡号
     * @param orderId      订单ID
     * @param patientId    患者ID
     * @param userPersonId 用户ID
     * @param orderFee     支付金额
     * @param payTime      支付时间
     * @param payType      支付类别
     * @param tradeNo      交易流水
     * @return
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> payConfirmForRegisterInsurance(String channelCode, String hospitalCode, String recordId, String openId, String orderId, String patientId, String userPersonId, String orderFee, String payTime, String payType, String tradeNo, String moneyPay) throws Exception {
        Map<String, Object> res = new HashMap<>(16);
        Map<String, Object> params = new HashMap<>(16);
        Map<String, Object> daoRes = new HashMap<>(16);
        params.put("channelCode", channelCode);
        params.put("id", recordId);
        daoRes = clinicAppointmentRecordDao.findOne(params);
        String registStatus = (String) daoRes.get("state");
        if (daoRes != null) {
            Map<String, Object> resMap = new HashMap<>(16);
            String method = "send";
            Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
            Transfer transfer = new PayConfirmForRegistInsuranceTransfer(method, client, "RegistTranConfirm");
            params.putAll(daoRes);
            params.put("patientId", patientId);
            params.put("orderFee", orderFee);
            params.put("tradeNo", tradeNo);
            params.put("payType", payType);
            params.put("moneyPay", moneyPay);
            resMap = transfer.transfer(params);
            String executeMessage = (String) resMap.get("message");
            if (!registStatus.equals("2")) {
                if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
                    Map<String, Object> daoParams = new HashMap<>(16);
                    Map<String, Object> billParams = new HashMap<>(16);
                    String tranNo = (String) resMap.get("tranNo");
                    res.putAll(resMap);
                    res.put(ResponseMessage.RES_CODE, "0");
                    res.put(ResponseMessage.MESSAGE_IN, "当日挂号支付确认成功");
                    res.put(ResponseMessage.MESSAGE, "当日挂号支付确认成功");
                    res.put(ResponseMessage.MESSAGE_OUT, "当日挂号支付确认成功");
                    daoParams.put("channelCode", channelCode);
                    daoParams.put("tranNo", tranNo);
                    daoParams.put("state", "2");
                    daoParams.put("id", recordId);
                    daoParams.put("modifyTime", DataFormatUtils.getTimeString(new Date()));
                    clinicAppointmentRecordDao.modify(daoParams);
                    Map<String, Object> findOneRes = clinicAppointmentRecordDao.findOne(daoParams);
                    billParams.put("billId", orderId);
                    billParams.put("hospitalCode", hospitalCode);
                    billParams.put("doctorCode", findOneRes.get("doctorCode"));
                    billParams.put("deptCode", findOneRes.get("deptCode"));
                    billParams.put("appointmentCode", recordId);
                    billParams.put("appointDate", DataFormatUtils.getTimeString((Date) findOneRes.get("appointDate")));
                    billParams.put("transactNo", tranNo);
                    billParams.put("orderId", findOneRes.get("rcptNo"));
                    billParams.put("patientId", patientId);
                    billParams.put("visitNo", findOneRes.get("visitNo"));
                    billParams.put("prescriptionNum", "");
                    billParams.put("channelCode", channelCode);
                    billParams.put("personId", findOneRes.get("personId"));
                    billParams.put("idCard", findOneRes.get("idCard"));
                    billParams.put("personName", findOneRes.get("name"));
                    billParams.put("phone", userPersonId);
                    billParams.put("username", userPersonId);
                    billParams.put("cardType", payType);
                    billParams.put("cardNum", openId);
                    billParams.put("patientType", findOneRes.get("patientType"));
                    billParams.put("totalCost", findOneRes.get("totalCost"));
                    billParams.put("tradeNo", tradeNo);
                    billParams.put("cost", orderFee);
                    billParams.put("insuranceAmount", findOneRes.get("insurPay"));
                    billParams.put("personalAmount", findOneRes.get("insurAccountPay"));
                    billParams.put("otherAmount", orderFee);
                    billParams.put("payWay", payType);
                    billParams.put("visitDate", DataFormatUtils.getTimeString((Date) findOneRes.get("appointDate")));
                    billParams.put("createTime", DataFormatUtils.getTimeString(new Date()));
                    billParams.put("payTime", payTime);
                    billParams.put("billTypeCode", "1");
                    billParams.put("payType", payType);
                    billParams.put("state", "0");
                    billingRecordDao.add(billParams);
                } else {
                    Map<String, Object> daoParams = new HashMap<>(16);
                    Map<String, Object> billParams = new HashMap<>(16);
                    daoParams.put("id", recordId);
                    clinicAppointmentRecordDao.modify(daoParams);
                    Map<String, Object> findOneRes = clinicAppointmentRecordDao.findOne(daoParams);
                    billParams.put("billId", orderId);
                    billParams.put("hospitalCode", hospitalCode);
                    billParams.put("doctorCode", findOneRes.get("doctorCode"));
                    billParams.put("deptCode", findOneRes.get("deptCode"));
                    billParams.put("appointmentCode", recordId);
                    billParams.put("appointDate", DataFormatUtils.getTimeString((Date) findOneRes.get("appointDate")));
//                billParams.put("transactNo", tranNo);
                    billParams.put("orderId", findOneRes.get("rcptNo"));
                    billParams.put("patientId", patientId);
                    billParams.put("visitNo", findOneRes.get("visitNo"));
                    billParams.put("prescriptionNum", "");
                    billParams.put("channelCode", channelCode);
                    billParams.put("personId", findOneRes.get("personId"));
                    billParams.put("idCard", findOneRes.get("idCard"));
                    billParams.put("personName", findOneRes.get("name"));
                    billParams.put("phone", userPersonId);
                    billParams.put("username", userPersonId);
                    billParams.put("cardType", payType);
                    billParams.put("cardNum", openId);
                    billParams.put("patientType", findOneRes.get("patientType"));
                    billParams.put("totalCost", findOneRes.get("totalCost"));
                    billParams.put("tradeNo", tradeNo);
                    billParams.put("cost", orderFee);
                    billParams.put("insuranceAmount", findOneRes.get("insurPay"));
                    billParams.put("personalAmount", findOneRes.get("insurAccountPay"));
                    billParams.put("otherAmount", orderFee);
                    billParams.put("payWay", payType);
                    billParams.put("visitDate", DataFormatUtils.getTimeString((Date) findOneRes.get("appointDate")));
                    billParams.put("createTime", DataFormatUtils.getTimeString(new Date()));
                    billParams.put("payTime", payTime);
                    billParams.put("billTypeCode", "1");
                    billParams.put("payType", payType);
                    billParams.put("state", "3");
                    billingRecordDao.add(billParams);
                    res.put(ResponseMessage.RES_CODE, "-23");
                    res.put(ResponseMessage.MESSAGE_IN, executeMessage);
                    res.put(ResponseMessage.MESSAGE, executeMessage);
                    res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
                }
            } else {
                res.put(ResponseMessage.RES_CODE, "0");
                res.put(ResponseMessage.MESSAGE, "成功");
                res.put(ResponseMessage.MESSAGE_IN, "成功");
                res.put(ResponseMessage.MESSAGE_OUT, "成功");
            }
        } else {
            res.put(ResponseMessage.RES_CODE, "-3");
            res.put(ResponseMessage.MESSAGE, "未找到" + recordId + "相关记录");
            res.put(ResponseMessage.MESSAGE_IN, "未找到" + recordId + "相关记录");
            res.put(ResponseMessage.MESSAGE_OUT, "未找到" + recordId + "相关记录");
        }
        return res;
    }

    /**
     * @param channelCode
     * @param hospitalCode
     * @return 患者住院信息查询
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> personInHos(String channelCode, String hospitalCode, String idNo) throws Exception {
        Map<String, Object> res = new HashMap<>(16);

        // 调用胸科院内前置服务或公司内部测试服务的方法名
        String method = callMethod;
        if (method == null || method.isEmpty()) method = "send";


        Map<String, Object> params = new HashMap<>(16);
        params.put("channelCode", channelCode);
        params.put("hospitalCode", hospitalCode);
        params.put("idNo", idNo);
        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
        Transfer transfer = new PersonInHosTransfer(method, client, "GetPatInHos");
        Map<String, Object> resMap = transfer.transfer(params);
        if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
            res.put("inPatientId", resMap.get("inPatientId"));
            res.put("patientId", resMap.get("patientId"));
            res.put("visitId", resMap.get("visitId"));
            res.put("name", resMap.get("name"));
            res.put("sex", resMap.get("sex"));
            res.put("dateOfBirth", resMap.get("dateOfBirth"));
            res.put("idNo", resMap.get("idNo"));
            res.put("mailingAddress", resMap.get("mailingAddress"));
            res.put("phoneNumberBussiness", resMap.get("phoneNumberBussiness"));
            res.put("nextOfKin", resMap.get("nextOfKin"));
            res.put("relationship", resMap.get("relationship"));
            res.put("nextOfKinPhone", resMap.get("nextOfKinPhone"));
            res.put("admissionDateTime", resMap.get("admissionDateTime"));
            res.put("dischargeDateTime", resMap.get("dischargeDateTime"));
            res.put("days", resMap.get("days"));
            res.put("deptAdmissionYo", resMap.get("deptAdmissionYo"));
            res.put("wardName", resMap.get("wardName"));
            res.put("bedNo", resMap.get("bedNo"));
            res.put("attendingDoctor", resMap.get("attendingDoctor"));
            res.put("nurseResponsibility", resMap.get("nurseResponsibility"));
            res.put("totalcharges", resMap.get("totalcharges"));
            res.put("totalprepay", resMap.get("totalprepay"));
            res.put("unsettled", resMap.get("unsettled"));
            res.put("settled", resMap.get("settled"));
            res.put("balance", resMap.get("balance"));
            res.put("status", resMap.get("status"));

//        res.put("inPatientId", "1111111");
//        res.put("patientId", "1111111");
//        res.put("visitId", "1111111");
//        res.put("name", "张三");
//        res.put("sex", "男");
//        res.put("dateOfBirth", "1992-02-01");
//        res.put("idNo", "1222222222222222");
//        res.put("mailingAddress", "无");
//        res.put("phoneNumberBussiness", "无");
//        res.put("nextOfKin", "无");
//        res.put("relationship", "无");
//        res.put("nextOfKinPhone", "14242232321");
//        res.put("admissionDateTime", "1992-02-01");
//        res.put("dischargeDateTime", "1992-02-03");
//        res.put("days", "3");
//        res.put("deptAdmissionYo", "15");
//        res.put("wardName", "222");
//        res.put("bedNo", "2");
//        res.put("attendingDoctor", "李四");
//        res.put("nurseResponsibility", "王五");
//        res.put("totalcharges", "20000");
//        res.put("totalprepay", "10000");
//        res.put("unsettled", "10000");
//        res.put("settled", "10000");
//        res.put("balance", "10000");
//        res.put("status", "");
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "查询成功 ");
            res.put(ResponseMessage.MESSAGE, "查询成功");
            res.put(ResponseMessage.MESSAGE_OUT, "查询成功");
        } else {
            String executeMessage = (String) resMap.get("message");
            res.put(ResponseMessage.RES_CODE, "-1");
            res.put(ResponseMessage.MESSAGE_IN, executeMessage);
            res.put(ResponseMessage.MESSAGE, executeMessage);
            res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
        }

        return res;
    }

    /**
     * @param channelCode
     * @param hospitalCode
     * @return 患者住院预交金记录查询
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> getPrePayments(String channelCode, String hospitalCode, String idNo) throws Exception {
        Map<String, Object> res = new HashMap<>(16);

        // 调用胸科院内前置服务或公司内部测试服务的方法名
        String method = callMethod;
        if (method == null || method.isEmpty()) method = "send";


        Map<String, Object> params = new HashMap<>(16);
        params.put("channelCode", channelCode);
        params.put("hospitalCode", hospitalCode);
        params.put("idNo", idNo);
        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
        Transfer transfer = new GetPrePaymentsTransfer_old(method, client, "GetPrePayments");
        Transfer transfer1 = new PersonInHosTransfer(method, client, "GetPatInHos");
        Map<String, Object> resMap = transfer.transfer(params);
        Map<String, Object> resMap1 = transfer1.transfer(params);

        if ((Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) && (Dialect.getSuccessfulState().equals(resMap1.get(ResponseMessage.RES_CODE)))) {
            List<Map<String, Object>> dataList = new ArrayList<>();
            List<Map<String, Object>> list = (List<Map<String, Object>>) resMap.get("list");
            if (list != null && list.size() > 0) {
                for (Map<String, Object> dataSubMap : list) {
                    Map<String, Object> paramsMap = new HashMap<>(16);
                    {
                        paramsMap.put("patientId", dataSubMap.get("patientId"));
                        paramsMap.put("visitId", dataSubMap.get("visitId"));
                        paramsMap.put("idNo", dataSubMap.get("idNo"));
                        paramsMap.put("rcptNo", dataSubMap.get("rcptNo"));
                        paramsMap.put("amount", dataSubMap.get("amount"));
                        paramsMap.put("payWay", dataSubMap.get("payWay"));
                        paramsMap.put("transactType", dataSubMap.get("transactType"));
                        paramsMap.put("winNo", dataSubMap.get("winNo"));
                        paramsMap.put("payDateTime", dataSubMap.get("payDateTime"));
                        paramsMap.put("cardNo", dataSubMap.get("cardNo"));
                        paramsMap.put("cardType", dataSubMap.get("cardType"));
                        paramsMap.put("tranNo", dataSubMap.get("tranNo"));
                        paramsMap.put("streamNo", dataSubMap.get("streamNo"));
                        paramsMap.put("reference", dataSubMap.get("reference"));
                        paramsMap.put("bankCode", dataSubMap.get("bankCode"));
                        paramsMap.put("terminalNumber", dataSubMap.get("terminalNumber"));
                        paramsMap.put("prepaymentBalance", dataSubMap.get("prepaymentBalance"));
                        dataList.add(paramsMap);
                    }
                }
            }
//        Map<String, Object> paramsMap = new HashMap<>(16);
//        paramsMap.put("patientId", "23213");
//        paramsMap.put("visitId", "12");
//        paramsMap.put("idNo", "213232321321312212");
//        paramsMap.put("rcptNo", "14532");
//        paramsMap.put("amount", "10000");
//        paramsMap.put("payWay", "微信");
//        paramsMap.put("transactType", "预交金");
//        paramsMap.put("winNo", "");
//        paramsMap.put("payDateTime", "2019-1-13");
//        paramsMap.put("cardNo", "");
//        paramsMap.put("cardType", "");
//        paramsMap.put("tranNo", "23123213213");
//        paramsMap.put("streamNo", "2321321321");
//        paramsMap.put("reference", "");
//        paramsMap.put("bankCode", "");
//        paramsMap.put("terminalNumber", "");
//        paramsMap.put("prepaymentBalance", "");
//        dataList.add(paramsMap);
            res.put("dataList", dataList);


//            if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
            res.put("inPatientId", resMap1.get("inPatientId"));
            res.put("patientId", resMap1.get("patientId"));
            res.put("visitId", resMap1.get("visitId"));
            res.put("name", resMap1.get("name"));
            res.put("sex", resMap1.get("sex"));
            res.put("dateOfBirth", resMap1.get("dateOfBirth"));
            res.put("idNo", resMap1.get("idNo"));
            res.put("mailingAddress", resMap1.get("mailingAddress"));
            res.put("phoneNumberBussiness", resMap1.get("phoneNumberBussiness"));
            res.put("nextOfKin", resMap1.get("nextOfKin"));
            res.put("relationship", resMap1.get("relationship"));
            res.put("nextOfKinPhone", resMap1.get("nextOfKinPhone"));
            res.put("admissionDateTime", resMap1.get("admissionDateTime"));
            res.put("dischargeDateTime", resMap1.get("dischargeDateTime"));
            res.put("days", resMap1.get("days"));
            res.put("deptAdmissionYo", resMap1.get("deptAdmissionYo"));
            res.put("wardName", resMap1.get("wardName"));
            res.put("bedNo", resMap1.get("bedNo"));
            res.put("attendingDoctor", resMap1.get("attendingDoctor"));
            res.put("nurseResponsibility", resMap1.get("nurseResponsibility"));
            res.put("totalcharges", resMap1.get("totalcharges"));
            res.put("totalprepay", resMap1.get("totalprepay"));
            res.put("unsettled", resMap1.get("unsettled"));
            res.put("settled", resMap1.get("settled"));
            res.put("balance", resMap1.get("balance"));
            res.put("status", resMap1.get("status"));
            res.put("phoneNumberHome", resMap1.get("phoneNumberHome"));

//        res.put("inPatientId", "1111111");
//        res.put("patientId", "1111111");
//        res.put("visitId", "1111111");
//        res.put("name", "张三");
//        res.put("sex", "男");
//        res.put("dateOfBirth", "1992-02-01");
//        res.put("idNo", "1222222222222222");
//        res.put("mailingAddress", "无");
//        res.put("phoneNumberBussiness", "无");
//        res.put("nextOfKin", "无");
//        res.put("relationship", "无");
//        res.put("nextOfKinPhone", "14242232321");
//        res.put("admissionDateTime", "1992-02-01");
//        res.put("dischargeDateTime", "1992-02-03");
//        res.put("days", "3");
//        res.put("deptAdmissionYo", "15");
//        res.put("wardName", "222");
//        res.put("bedNo", "2");
//        res.put("attendingDoctor", "李四");
//        res.put("nurseResponsibility", "王五");
//        res.put("totalcharges", "20000");
//        res.put("totalprepay", "10000");
//        res.put("unsettled", "10000");
//        res.put("settled", "10000");
//        res.put("balance", "10000");
//        res.put("status", "");
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "查询成功 ");
            res.put(ResponseMessage.MESSAGE, "查询成功");
            res.put(ResponseMessage.MESSAGE_OUT, "查询成功");
        } else {
            String executeMessage = (String) resMap.get("message");
            res.put(ResponseMessage.RES_CODE, "-1");
            res.put(ResponseMessage.MESSAGE_IN, executeMessage);
            res.put(ResponseMessage.MESSAGE, executeMessage);
            res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
        }

        return res;
    }

    /**
     * @param channelCode
     * @param hospitalCode
     * @return 患者住院预交金缴纳
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> doPrePayments(String channelCode, String hospitalCode, String idCard, String patientId, String amount, String tranNo, String moneyType, String streamNo) throws Exception {
        Map<String, Object> res = new HashMap<>(16);

        // 调用胸科院内前置服务或公司内部测试服务的方法名
        String method = callMethod;
        if (method == null || method.isEmpty()) method = "send";


        Map<String, Object> params = new HashMap<>(16);
        params.put("channelCode", channelCode);
        params.put("hospitalCode", hospitalCode);
        params.put("idNo", idCard);
        params.put("patientId", patientId);
        params.put("amount", amount);
        params.put("tranNo", tranNo);
        params.put("moneyType", moneyType);
        params.put("streamNo", streamNo);
        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
        Transfer transfer = new DoPrePaymentsTransfer_old(method, client, "DoPrePayments");
        Map<String, Object> resMap = transfer.transfer(params);
        if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
            res.put("rcptNo", resMap.get("rcptNo"));

//        res.put("rcptNo", "23121");
            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "预交金缴纳成功 ");
            res.put(ResponseMessage.MESSAGE, "预交金缴纳成功");
            res.put(ResponseMessage.MESSAGE_OUT, "预交金缴纳成功");
        } else {
            String executeMessage = (String) resMap.get("message");
            res.put(ResponseMessage.RES_CODE, "-1");
            res.put(ResponseMessage.MESSAGE_IN, executeMessage);
            res.put(ResponseMessage.MESSAGE, executeMessage);
            res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
        }

        return res;
    }



    /**
     * 提取创建患者数据
     *
     * @param channelCode  渠道编码
     * @param hospitalCode 医院编码
     * @param idNo 身份证号
     * @param name 姓名
     * @param age 年龄
     * @param birthday 生日
     * @param sex 性别，中文（男、女、未知）
     * @param address 住址
     * @param nation 民族，中文（汉族，回族等）
     * @param birthPlace 出生地，代码
     * @param zipCode 邮政编码
     * @param phoneNumberHome 手机号码
     * @param identity 身份，中文
     * @param chargeType 费别，中文
     * @param maritalStatus 婚姻状况，代码
     * @param insurNo 医保卡号
     * @param insurPwd 医保卡密码
     * @param cardNo 卡号
     * @param cardType 卡类型
     * @param personNo 个人编码
     * @param isAnonymous 是否匿名
     * @return
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, readOnly = false)
    public Map<String, Object> establishPatient(String channelCode, String hospitalCode, String idNo, String name, String age, String birthday, String sex, String address, String nation, String birthPlace, String zipCode, String phoneNumberHome, String identity, String chargeType, String maritalStatus, String insurNo, String insurPwd, String cardNo, String cardType, String personNo, String isAnonymous) throws Exception {
        Map<String, Object> res = new HashMap<>(16);

        // 调用胸科院内前置服务或公司内部测试服务的方法名
        String method = callMethod;
        if (method == null || method.isEmpty()) method = "send";


        // 拼接入参：微信
        Map<String, Object> params = new HashMap<>(16);

        // 系统编码：微信前端区分医院用
        params.put("channelCode", channelCode);
        // 医院代码：微信后端区分医院用
        params.put("hospitalCode", hospitalCode);

        // 身份证号
        params.put("idNo", idNo);
        // 姓名
        params.put("name", name);
        // 年龄
        params.put("age", age);
        // 生日
        params.put("birthday", birthday);
        // 性别，中文（男、女、未知）
        params.put("sex", sex);
        // 住址
        params.put("address", address);
        // 民族，中文（汉族，回族等）
        params.put("nation", nation);
        // 出生地，代码
        params.put("birthPlace", birthPlace);
        // 邮政编码
        params.put("zipCode", zipCode);
        // 手机号码
        params.put("phoneNumberHome", phoneNumberHome);
        // 身份，中文
        params.put("identity", identity);
        // 费别，中文
        params.put("chargeType", chargeType);
        // 婚姻状况，代码
        params.put("maritalStatus", maritalStatus);
        // 医保卡号
        params.put("insurNo", insurNo);
        // 医保卡密码
        params.put("insurPwd", insurPwd);
        // 卡号
        params.put("cardNo", cardNo);
        // 卡类型
        params.put("cardType", cardType);
        // 个人编码
        params.put("personNo", personNo);
        // 是否匿名
        params.put("isAnonymous", isAnonymous);

        // 获取服务的连接：HIS前置
        Client client = WsClientFactory.getInstance().getWsClient(hisWsUrl);
        // 调用服务[hisWsUrl]的方法
        Transfer transfer = new EstablishPatientTransfer(method, client, "EstablishPatient");

        Map<String, Object> resMap = transfer.transfer(params);

        // 获取报文的具体项目：HIS前置
        if (Dialect.getSuccessfulState().equals(resMap.get(ResponseMessage.RES_CODE))) {
            // 患者ID
            res.put("patientId", resMap.get("patientId"));

            res.put(ResponseMessage.RES_CODE, "0");
            res.put(ResponseMessage.MESSAGE_IN, "提取创建患者数据：成功");
            res.put(ResponseMessage.MESSAGE, "提取创建患者数据：成功");
            res.put(ResponseMessage.MESSAGE_OUT, "提取创建患者数据：成功");
        }  else if (Dialect.getSuccessfulZero().equals(resMap.get(ResponseMessage.RES_CODE))) {
            res.put(ResponseMessage.RES_CODE, "1403");
            res.put(ResponseMessage.MESSAGE_IN, "提取创建患者数据：成功");
            res.put(ResponseMessage.MESSAGE, "提取创建患者数据：成功");
            res.put(ResponseMessage.MESSAGE_OUT, "提取创建患者数据：成功");
        } else {
            String executeMessage = (String) resMap.get("message");
            res.put(ResponseMessage.RES_CODE, "-1");
            res.put(ResponseMessage.MESSAGE_IN, executeMessage);
            res.put(ResponseMessage.MESSAGE, executeMessage);
            res.put(ResponseMessage.MESSAGE_OUT, executeMessage);
        }

        return res;
    }


}